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);
126 std::regex envVarExpr(R
"(\$\{(.+?)\})");
130 std::string strIter = str;
133 while (std::regex_search(strIter, match, envVarExpr)) {
134 std::string varName = match[1];
137 std::string varValue;
138 if (std::getenv(varName.c_str()) !=
nullptr) {
139 varValue = std::getenv(varName.c_str());
143 str = std::regex_replace(str, std::regex(
"\\$\\{" + varName +
"\\}"), varValue);
146 strIter = match.suffix();
154 std::ostringstream oss;
160 sprintf(buffer,
"%02i:", (time / 3600));
163 sprintf(buffer,
"%02i:", (time / 60));
166 sprintf(buffer,
"%02i", time);
174 return str.compare(0, prefix.length(), prefix) == 0;
180 if (str.length() >= suffix.length()) {
181 return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
190 std::string result =
replace(orig,
"&",
"&");
191 result =
replace(result,
">",
">");
192 result =
replace(result,
"<",
"<");
193 result =
replace(result,
"\"",
""");
194 if (maskDoubleHyphen) {
195 result =
replace(result,
"--",
"--");
197 for (
char invalid =
'\1'; invalid <
' '; invalid++) {
198 result =
replace(result, std::string(1, invalid).c_str(),
"");
200 return replace(result,
"'",
"'");
206 std::ostringstream out;
208 for (
int i = 0; i < (int)toEncode.length(); ++i) {
209 const char t = toEncode.at(i);
211 if ((encodeWhich !=
"" && encodeWhich.find(t) == std::string::npos) ||
212 (encodeWhich ==
"" &&
213 ((t >= 45 && t <= 57) ||
214 (t >= 65 && t <= 90) ||
216 (t >= 97 && t <= 122) ||
219 out << toEncode.at(i);
231 std::ostringstream out;
233 for (
int i = 0; i < (int)toDecode.length(); ++i) {
234 if (toDecode.at(i) ==
'%') {
235 std::string str(toDecode.substr(i + 1, 2));
239 out << toDecode.at(i);
252 s <<
"%" << std::setw(2) << std::setfill(
'0') << std::hex << i;
262 std::istringstream in(str);
268 return static_cast<unsigned char>(c);
274 long long int result =
toLong(sData);
275 if (result > std::numeric_limits<int>::max() || result < std::numeric_limits<int>::min()) {
284 if (sData.length() == 0) {
293 const char*
const data = sData.c_str();
294 if (data == 0 || data[0] == 0) {
300 long long int ret = _strtoi64(data, &end, 10);
302 long long int ret = strtoll(data, &end, 10);
304 if (errno == ERANGE) {
308 if ((
int)(end - data) != (
int)strlen(data)) {
317 if (sData.length() == 0) {
323 if (sData[0] ==
'#') {
324 result = std::stoi(sData.substr(1), &idx, 16);
327 result = std::stoi(sData, &idx, 16);
332 if (idx != sData.length()) {
341 if (sData.size() == 0) {
346 const double result = std::stod(sData, &idx);
347 if (idx != sData.size()) {
361 if (sData.length() == 0) {
370 if (sData.length() == 0) {
373 std::string s = sData;
375 for (
int i = 0; i < (int)s.length(); i++) {
376 s[i] = (char)::tolower((
char)s[i]);
378 if (s ==
"1" || s ==
"yes" || s ==
"true" || s ==
"on" || s ==
"x" || s ==
"t") {
380 }
else if (s ==
"0" || s ==
"no" || s ==
"false" || s ==
"off" || s ==
"-" || s ==
"f") {
396 #if _XERCES_VERSION < 30100
398 std::string result(t);
399 XERCES_CPP_NAMESPACE::XMLString::release(&t);
403 XERCES_CPP_NAMESPACE::TranscodeToStr utf8(data,
"UTF-8");
404 return reinterpret_cast<const char*
>(utf8.str());
405 }
catch (XERCES_CPP_NAMESPACE::TranscodingException&) {
414 std::string result = s;
415 result.erase(0, s.find_first_not_of(t));
421 std::string result = s;
422 result.erase(s.find_last_not_of(t) + 1);
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::string transcode(const XMLCh *const qname)
static std::string urlEncode(const std::string &url, const std::string encodeWhich="")
static std::string charToHex(unsigned char c)
static std::string urlDecode(const std::string &encoded)
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,...
static double toDoubleSecure(const std::string &sData, const double def)
converts a string into the integer value described by it
static std::string replace(std::string str, const char *what, const char *by)
static std::string trim(const std::string s, const std::string &t=" \t\n")
remove leading and trailing whitespace
static std::string trim_right(const std::string s, const std::string &t=" \t\n")
remove trailing whitespace from string
static std::string trim_left(const std::string s, const std::string &t=" \t\n")
remove leading whitespace from string
static std::string substituteEnvironment(std::string str)
static std::string toTimeString(int time)
Builds a time string (hh:mm:ss) from the given seconds.
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...
static double toDouble(const std::string &sData)
converts a string into the double 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 to_lower_case(std::string str)
Transfers the content to lower case.
static std::string latin1_to_utf8(std::string str)
Transfers from Latin 1 (ISO-8859-1) to UTF-8.
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
static std::string convertUmlaute(std::string str)
Converts german "Umlaute" to their latin-version.
static unsigned char hexToChar(const std::string &str)
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static std::string emptyString
An empty string.
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
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 int toIntSecure(const std::string &sData, int def)
converts a string into the integer value described by it
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter