31 #include <xercesc/util/TransService.hpp>
32 #include <xercesc/util/TranscodingException.hpp>
49 const std::string::size_type endpos = str.find_last_not_of(
" \t\n\r");
50 if (std::string::npos != endpos) {
51 const int startpos = (int)str.find_first_not_of(
" \t\n\r");
52 return str.substr(startpos, endpos - startpos + 1);
60 for (
int i = 0; i < (int)str.length(); i++) {
61 if (str[i] >=
'A' && str[i] <=
'Z') {
62 str[i] = str[i] +
'a' -
'A';
73 for (
int i = 0; i < (int)str.length(); i++) {
74 const unsigned char c = str[i];
78 result += (char)(0xc2 + (c > 0xbf));
79 result += (char)((c & 0x3f) + 0x80);
88 str =
replace(str,
"\xE4",
"ae");
89 str =
replace(str,
"\xC4",
"Ae");
90 str =
replace(str,
"\xF6",
"oe");
91 str =
replace(str,
"\xD6",
"Oe");
92 str =
replace(str,
"\xFC",
"ue");
93 str =
replace(str,
"\xDC",
"Ue");
94 str =
replace(str,
"\xDF",
"ss");
95 str =
replace(str,
"\xC9",
"E");
96 str =
replace(str,
"\xE9",
"e");
97 str =
replace(str,
"\xC8",
"E");
98 str =
replace(str,
"\xE8",
"e");
107 const std::string what_tmp(what);
108 const std::string by_tmp(by);
109 std::string::size_type idx = str.find(what);
110 const int what_len = (int)what_tmp.length();
112 const int by_len = (int)by_tmp.length();
113 while (idx != std::string::npos) {
114 str = str.replace(idx, what_len, by);
115 idx = str.find(what, idx + by_len);
127 std::regex envVarExpr(R
"(\$\{(.+?)\})");
131 std::string strIter = str;
134 while (std::regex_search(strIter, match, envVarExpr)) {
135 std::string varName = match[1];
138 std::string varValue;
139 if (std::getenv(varName.c_str()) !=
nullptr) {
140 varValue = std::getenv(varName.c_str());
144 str = std::regex_replace(str, std::regex(
"\\$\\{" + varName +
"\\}"), varValue);
147 strIter = match.suffix();
155 std::ostringstream oss;
161 sprintf(buffer,
"%02i:", (time / 3600));
164 sprintf(buffer,
"%02i:", (time / 60));
167 sprintf(buffer,
"%02i", time);
175 return str.compare(0, prefix.length(), prefix) == 0;
181 if (str.length() >= suffix.length()) {
182 return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
191 std::string result =
replace(orig,
"&",
"&");
192 result =
replace(result,
">",
">");
193 result =
replace(result,
"<",
"<");
194 result =
replace(result,
"\"",
""");
195 if (maskDoubleHyphen) {
196 result =
replace(result,
"--",
"--");
198 for (
char invalid =
'\1'; invalid <
' '; invalid++) {
199 result =
replace(result, std::string(1, invalid).c_str(),
"");
201 return replace(result,
"'",
"'");
207 std::ostringstream out;
209 for (
int i = 0; i < (int)toEncode.length(); ++i) {
210 const char t = toEncode.at(i);
212 if ((encodeWhich !=
"" && encodeWhich.find(t) == std::string::npos) ||
213 (encodeWhich ==
"" &&
214 ((t >= 45 && t <= 57) ||
215 (t >= 65 && t <= 90) ||
217 (t >= 97 && t <= 122) ||
220 out << toEncode.at(i);
232 std::ostringstream out;
234 for (
int i = 0; i < (int)toDecode.length(); ++i) {
235 if (toDecode.at(i) ==
'%') {
236 std::string str(toDecode.substr(i + 1, 2));
240 out << toDecode.at(i);
253 s <<
"%" << std::setw(2) << std::setfill(
'0') << std::hex << i;
264 std::istringstream in(str);
269 throw std::runtime_error(
"stream decode failure");
273 return static_cast<unsigned char>(c);
279 long long int result =
toLong(sData);
280 if (result > std::numeric_limits<int>::max() || result < std::numeric_limits<int>::min()) {
289 if (sData.length() == 0) {
298 const char*
const data = sData.c_str();
299 if (data == 0 || data[0] == 0) {
305 long long int ret = _strtoi64(data, &end, 10);
307 long long int ret = strtoll(data, &end, 10);
309 if (errno == ERANGE) {
313 if ((
int)(end - data) != (
int)strlen(data)) {
322 if (sData.length() == 0) {
328 if (sData[0] ==
'#') {
329 result = std::stoi(sData.substr(1), &idx, 16);
332 result = std::stoi(sData, &idx, 16);
337 if (idx != sData.length()) {
346 if (sData.size() == 0) {
351 const double result = std::stod(sData, &idx);
352 if (idx != sData.size()) {
366 if (sData.length() == 0) {
375 if (sData.length() == 0) {
378 std::string s = sData;
380 for (
int i = 0; i < (int)s.length(); i++) {
381 s[i] = (char)::tolower((
char)s[i]);
383 if (s ==
"1" || s ==
"yes" || s ==
"true" || s ==
"on" || s ==
"x" || s ==
"t") {
385 }
else if (s ==
"0" || s ==
"no" || s ==
"false" || s ==
"off" || s ==
"-" || s ==
"f") {
401 #if _XERCES_VERSION < 30100
403 std::string result(t);
404 XERCES_CPP_NAMESPACE::XMLString::release(&t);
408 XERCES_CPP_NAMESPACE::TranscodeToStr utf8(data,
"UTF-8");
409 return reinterpret_cast<const char*>(utf8.str());
410 }
catch (XERCES_CPP_NAMESPACE::TranscodingException&) {