30 #include <xercesc/util/TransService.hpp>
31 #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 return std::string(
MAX2(0, length - (
int)str.size()), padding) + str;
197 std::string result =
replace(orig,
"&",
"&");
198 result =
replace(result,
">",
">");
199 result =
replace(result,
"<",
"<");
200 result =
replace(result,
"\"",
""");
201 if (maskDoubleHyphen) {
202 result =
replace(result,
"--",
"--");
204 for (
char invalid =
'\1'; invalid <
' '; invalid++) {
205 result =
replace(result, std::string(1, invalid).c_str(),
"");
207 return replace(result,
"'",
"'");
213 std::ostringstream out;
215 for (
int i = 0; i < (int)toEncode.length(); ++i) {
216 const char t = toEncode.at(i);
218 if ((encodeWhich !=
"" && encodeWhich.find(t) == std::string::npos) ||
219 (encodeWhich ==
"" &&
220 ((t >= 45 && t <= 57) ||
221 (t >= 65 && t <= 90) ||
223 (t >= 97 && t <= 122) ||
226 out << toEncode.at(i);
238 std::ostringstream out;
240 for (
int i = 0; i < (int)toDecode.length(); ++i) {
241 if (toDecode.at(i) ==
'%') {
242 std::string str(toDecode.substr(i + 1, 2));
246 out << toDecode.at(i);
259 s <<
"%" << std::setw(2) << std::setfill(
'0') << std::hex << i;
269 std::istringstream in(str);
275 return static_cast<unsigned char>(c);
281 long long int result =
toLong(sData);
282 if (result > std::numeric_limits<int>::max() || result < std::numeric_limits<int>::min()) {
291 if (sData.length() == 0) {
300 const char*
const data = sData.c_str();
301 if (data == 0 || data[0] == 0) {
307 long long int ret = _strtoi64(data, &end, 10);
309 long long int ret = strtoll(data, &end, 10);
311 if (errno == ERANGE) {
315 if ((
int)(end - data) != (
int)strlen(data)) {
324 if (sData.length() == 0) {
330 if (sData[0] ==
'#') {
331 result = std::stoi(sData.substr(1), &idx, 16);
334 result = std::stoi(sData, &idx, 16);
339 if (idx != sData.length()) {
348 if (sData.size() == 0) {
353 const double result = std::stod(sData, &idx);
354 if (idx != sData.size()) {
368 if (sData.length() == 0) {
377 if (sData.length() == 0) {
380 std::string s = sData;
382 for (
int i = 0; i < (int)s.length(); i++) {
383 s[i] = (char)::tolower((
char)s[i]);
385 if (s ==
"1" || s ==
"yes" || s ==
"true" || s ==
"on" || s ==
"x" || s ==
"t") {
387 }
else if (s ==
"0" || s ==
"no" || s ==
"false" || s ==
"off" || s ==
"-" || s ==
"f") {
403 #if _XERCES_VERSION < 30100
405 std::string result(t);
406 XERCES_CPP_NAMESPACE::XMLString::release(&t);
410 XERCES_CPP_NAMESPACE::TranscodeToStr utf8(data,
"UTF-8");
411 return reinterpret_cast<const char*
>(utf8.str());
412 }
catch (XERCES_CPP_NAMESPACE::TranscodingException&) {
421 #if _XERCES_VERSION > 30100
424 myLCPTranscoder = XERCES_CPP_NAMESPACE::XMLPlatformUtils::fgTransService->makeNewLCPTranscoder(XERCES_CPP_NAMESPACE::XMLPlatformUtils::fgMemoryManager);
429 }
catch (XERCES_CPP_NAMESPACE::TranscodingException&) {}
437 #if _XERCES_VERSION > 30100
440 myLCPTranscoder = XERCES_CPP_NAMESPACE::XMLPlatformUtils::fgTransService->makeNewLCPTranscoder(XERCES_CPP_NAMESPACE::XMLPlatformUtils::fgMemoryManager);
443 XERCES_CPP_NAMESPACE::TranscodeFromStr utf8(
reinterpret_cast<const XMLByte*
>(utf8String.c_str()), utf8String.size(),
"UTF-8");
446 }
catch (XERCES_CPP_NAMESPACE::TranscodingException&) {}
454 std::string result = s;
455 result.erase(0, s.find_first_not_of(t));
461 std::string result = s;
462 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 void resetTranscoder()
must be called when shutting down the xml subsystem
static XERCES_CPP_NAMESPACE::XMLLCPTranscoder * myLCPTranscoder
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 padFront(const std::string &str, int length, char padding)
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 std::string transcodeToLocal(const std::string &utf8String)
convert a string from UTF-8 to the local codepage
static int toIntSecure(const std::string &sData, int def)
converts a string into the integer value described by it
static std::string transcodeFromLocal(const std::string &localString)
convert a string from the local codepage to UTF-8
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