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) {
273 long long int ret = _strtoi64(data, &end, 10);
275 long long int ret = strtoll(data, &end, 10);
277 if (errno == ERANGE) {
281 if ((
int)(end - data) != (
int)strlen(data)) {
290 if (sData.length() == 0) {
296 if (sData[0] ==
'#') {
297 result = std::stoi(sData.substr(1), &idx, 16);
300 result = std::stoi(sData, &idx, 16);
305 if (idx != sData.length()) {
314 if (sData.size() == 0) {
319 const double result = std::stod(sData, &idx);
320 if (idx != sData.size()) {
334 if (sData.length() == 0) {
343 if (sData.length() == 0) {
346 std::string s = sData;
348 for (
int i = 0; i < (int)s.length(); i++) {
349 s[i] = (char)::tolower((
char)s[i]);
351 if (s ==
"1" || s ==
"yes" || s ==
"true" || s ==
"on" || s ==
"x" || s ==
"t") {
353 }
else if (s ==
"0" || s ==
"no" || s ==
"false" || s ==
"off" || s ==
"-" || s ==
"f") {
369 #if _XERCES_VERSION < 30100
371 std::string result(t);
372 XERCES_CPP_NAMESPACE::XMLString::release(&t);
376 XERCES_CPP_NAMESPACE::TranscodeToStr utf8(data,
"UTF-8");
377 return reinterpret_cast<const char*>(utf8.str());
378 }
catch (XERCES_CPP_NAMESPACE::TranscodingException&) {