30 #include <xercesc/util/TransService.hpp> 31 #include <xercesc/util/TranscodingException.hpp> 48 const std::string::size_type endpos = str.find_last_not_of(
" \t\n\r");
49 if (std::string::npos != endpos) {
50 const int startpos = (int)str.find_first_not_of(
" \t\n\r");
51 return str.substr(startpos, endpos - startpos + 1);
59 for (
int i = 0; i < (int)str.length(); i++) {
60 if (str[i] >=
'A' && str[i] <=
'Z') {
61 str[i] = str[i] +
'a' -
'A';
72 for (
int i = 0; i < (int)str.length(); i++) {
73 const unsigned char c = str[i];
77 result += (char)(0xc2 + (c > 0xbf));
78 result += (char)((c & 0x3f) + 0x80);
87 str =
replace(str,
"\xE4",
"ae");
88 str =
replace(str,
"\xC4",
"Ae");
89 str =
replace(str,
"\xF6",
"oe");
90 str =
replace(str,
"\xD6",
"Oe");
91 str =
replace(str,
"\xFC",
"ue");
92 str =
replace(str,
"\xDC",
"Ue");
93 str =
replace(str,
"\xDF",
"ss");
94 str =
replace(str,
"\xC9",
"E");
95 str =
replace(str,
"\xE9",
"e");
96 str =
replace(str,
"\xC8",
"E");
97 str =
replace(str,
"\xE8",
"e");
106 const std::string what_tmp(what);
107 const std::string by_tmp(by);
108 std::string::size_type idx = str.find(what);
109 const int what_len = (int)what_tmp.length();
111 const int by_len = (int)by_tmp.length();
112 while (idx != std::string::npos) {
113 str = str.replace(idx, what_len, by);
114 idx = str.find(what, idx + by_len);
123 std::ostringstream oss;
129 sprintf(buffer,
"%02i:", (time / 3600));
132 sprintf(buffer,
"%02i:", (time / 60));
135 sprintf(buffer,
"%02i", time);
143 return str.compare(0, prefix.length(), prefix) == 0;
149 if (str.length() >= suffix.length()) {
150 return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
159 std::string result =
replace(orig,
"&",
"&");
160 result =
replace(result,
">",
">");
161 result =
replace(result,
"<",
"<");
162 result =
replace(result,
"\"",
""");
163 if (maskDoubleHyphen) {
164 result =
replace(result,
"--",
"--");
166 for (
char invalid =
'\1'; invalid <
' '; invalid++) {
167 result =
replace(result, std::string(1, invalid).c_str(),
"");
169 return replace(result,
"'",
"'");
175 std::ostringstream out;
177 for (
int i = 0; i < (int)toEncode.length(); ++i) {
178 const char t = toEncode.at(i);
180 if ((encodeWhich !=
"" && encodeWhich.find(t) == std::string::npos) ||
181 (encodeWhich ==
"" &&
182 ((t >= 45 && t <= 57) ||
183 (t >= 65 && t <= 90) ||
185 (t >= 97 && t <= 122) ||
188 out << toEncode.at(i);
200 std::ostringstream out;
202 for (
int i = 0; i < (int)toDecode.length(); ++i) {
203 if (toDecode.at(i) ==
'%') {
204 std::string str(toDecode.substr(i + 1, 2));
208 out << toDecode.at(i);
221 s <<
"%" << std::setw(2) << std::setfill(
'0') << std::hex << i;
232 std::istringstream in(str);
237 throw std::runtime_error(
"stream decode failure");
241 return static_cast<unsigned char>(c);
247 long long int result =
toLong(sData);
248 if (result > std::numeric_limits<int>::max() || result < std::numeric_limits<int>::min()) {
257 if (sData.length() == 0) {
266 const char*
const data = sData.c_str();
267 if (data == 0 || data[0] == 0) {
272 long long int ret = _strtoi64(data, &end, 10);
274 long long int ret = strtoll(data, &end, 10);
276 if (errno == ERANGE) {
280 if ((
int)(end - data) != (
int)strlen(data)) {
289 if (sData.length() == 0) {
295 if (sData[0] ==
'#') {
296 result = std::stoi(sData.substr(1), &idx, 16);
299 result = std::stoi(sData, &idx, 16);
304 if (idx != sData.length()) {
313 if (sData.size() == 0) {
318 const double result = std::stod(sData, &idx);
319 if (idx != sData.size()) {
333 if (sData.length() == 0) {
342 if (sData.length() == 0) {
345 std::string s = sData;
347 for (
int i = 0; i < (int)s.length(); i++) {
348 s[i] = (char)::tolower((
char)s[i]);
350 if (s ==
"1" || s ==
"yes" || s ==
"true" || s ==
"on" || s ==
"x" || s ==
"t") {
352 }
else if (s ==
"0" || s ==
"no" || s ==
"false" || s ==
"off" || s ==
"-" || s ==
"f") {
368 #if _XERCES_VERSION < 30100 369 char* t = XERCES_CPP_NAMESPACE::XMLString::transcode(data);
370 std::string result(t);
371 XERCES_CPP_NAMESPACE::XMLString::release(&t);
375 XERCES_CPP_NAMESPACE::TranscodeToStr utf8(data,
"UTF-8");
376 return reinterpret_cast<const char*
>(utf8.str());
377 }
catch (XERCES_CPP_NAMESPACE::TranscodingException&) {
static unsigned char hexToChar(const std::string &str)
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
static int toIntSecure(const std::string &sData, int def)
converts a string into the integer value described by it
static std::string toTimeString(int time)
Builds a time string (hh:mm:ss) from the given seconds.
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
static std::string urlEncode(const std::string &url, const std::string encodeWhich="")
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter ...
static std::string transcode(const XMLCh *const data)
converts a 0-terminated XMLCh* array (usually UTF-16, stemming from Xerces) into std::string in UTF-8...
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
static std::string emptyString
An empty string.
static std::string replace(std::string str, const char *what, const char *by)
static std::string to_lower_case(std::string str)
Transfers the content to lower case.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
static long long int toLong(const std::string &sData)
converts a string into the long value described by it by calling the char-type converter, which
static std::string urlDecode(const std::string &encoded)
static std::string charToHex(unsigned char c)
static double toDoubleSecure(const std::string &sData, const double def)
converts a string into the integer value described by it
static int hexToInt(const std::string &sData)
converts a string with a hex value into the integer value described by it by calling the char-type co...