replace a few string algorithms with boost utilities

This commit is contained in:
Andrzej Rybczak
2012-10-04 22:33:17 +02:00
parent 5908250c18
commit 8db773cfec
28 changed files with 138 additions and 198 deletions

View File

@@ -20,6 +20,7 @@
#include <locale>
#include "comparators.h"
#include "utility/string.h"
namespace {//

View File

@@ -18,8 +18,9 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <boost/algorithm/string/replace.hpp>
#include "utility/html.h"
#include "utility/string.h"
//#include "utility/string.h"
std::string unescapeHtmlUtf8(const std::string &data)
{
@@ -58,10 +59,10 @@ void stripHtmlTags(std::string &s)
size_t j = s.find(">", i)+1;
s.replace(i, j-i, "");
}
replace(s, "&#039;", "'");
replace(s, "&amp;", "&");
replace(s, "&quot;", "\"");
replace(s, "&nbsp;", " ");
boost::replace_all(s, "&#039;", "'");
boost::replace_all(s, "&amp;", "&");
boost::replace_all(s, "&quot;", "\"");
boost::replace_all(s, "&nbsp;", " ");
for (size_t i = 0; i < s.length(); ++i)
{
if (erase)

View File

@@ -1,75 +0,0 @@
/***************************************************************************
* Copyright (C) 2008-2012 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <string>
#include "string.h"
#ifndef NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H
#define NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H
template <typename R> struct intTo { };
template <> struct intTo<std::string> {
static std::string apply(int n) {
return print<32, std::string>::apply("%d", n);
}
};
template <> struct intTo<std::wstring> {
static std::wstring apply(int n) {
return print<32, std::wstring>::apply(L"%d", n);
}
};
template <typename R> struct longIntTo { };
template <> struct longIntTo<std::string> {
static std::string apply(long int n) {
return print<32, std::string>::apply("%ld", n);
}
};
template <> struct longIntTo<std::wstring> {
static std::wstring apply(long int n) {
return print<32, std::wstring>::apply(L"%ld", n);
}
};
template <typename R> struct unsignedIntTo { };
template <> struct unsignedIntTo<std::string> {
static std::string apply(unsigned int n) {
return print<32, std::string>::apply("%u", n);
}
};
template <> struct unsignedIntTo<std::wstring> {
static std::wstring apply(unsigned int n) {
return print<32, std::wstring>::apply(L"%u", n);
}
};
template <typename R> struct unsignedLongIntTo { };
template <> struct unsignedLongIntTo<std::string> {
static std::string apply(unsigned long int n) {
return print<32, std::string>::apply("%lu", n);
}
};
template <> struct unsignedLongIntTo<std::wstring> {
static std::wstring apply(unsigned long int n) {
return print<32, std::wstring>::apply(L"%lu", n);
}
};
#endif // NCMPCPP_UTILITY_NUMERIC_CONVERSIONS_H

View File

@@ -31,47 +31,8 @@ template <size_t N> size_t const_strlen(const char (&)[N]) {
return N-1;
}
template <size_t N, typename T> struct print { };
template <size_t N> struct print<N, std::string> {
static std::string apply(const char *format, ...) GNUC_PRINTF(1, 2) {
char buf[N];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf)/sizeof(char), format, args);
va_end(args);
return buf;
}
};
template <size_t N> struct print<N, std::wstring> {
static std::wstring apply(const wchar_t *format, ...) {
wchar_t buf[N];
va_list args;
va_start(args, format);
vswprintf(buf, sizeof(buf)/sizeof(wchar_t), format, args);
va_end(args);
return buf;
}
};
template <typename CharT>
std::basic_string<CharT> lowercase(std::basic_string<CharT> s)
{
std::locale loc;
const std::ctype<CharT> &ct = std::use_facet< std::ctype<CharT> >(loc);
for (auto it = s.begin(); it != s.end(); ++it)
*it = ct.tolower(*it);
return s;
}
int stringToInt(const std::string &s);
long stringToLongInt(const std::string &s);
bool isInteger(const char *s, bool accept_signed);
std::vector<std::string> split(const std::string &s, const std::string &delimiter);
void replace(std::string &s, const std::string &from, const std::string &to);
void trim(std::string &s);
std::string getBasename(const std::string &path);
std::string getParentDirectory(const std::string &path);
std::string getSharedDirectory(const std::string &dir1, const std::string &dir2);