41 #ifdef CHECK_MEMORY_LEAKS 43 #endif // CHECK_MEMORY_LEAKS 57 const size_t endpos = str.find_last_not_of(
" \t\n\r");
58 if (std::string::npos != endpos) {
59 const size_t startpos = str.find_first_not_of(
" \t\n\r");
60 return str.substr(startpos, endpos - startpos + 1);
68 for (
size_t i = 0; i < str.length(); i++) {
69 if (str[i] >=
'A' && str[i] <=
'Z') {
70 str[i] = str[i] +
'a' -
'A';
81 for (
size_t i = 0; i < str.length(); i++) {
82 const unsigned char c = str[i];
86 result += (char)(0xc2 + (c > 0xbf));
87 result += (char)((c & 0x3f) + 0x80);
96 str =
replace(str,
"\xE4",
"ae");
97 str =
replace(str,
"\xC4",
"Ae");
98 str =
replace(str,
"\xF6",
"oe");
99 str =
replace(str,
"\xD6",
"Oe");
100 str =
replace(str,
"\xFC",
"ue");
101 str =
replace(str,
"\xDC",
"Ue");
102 str =
replace(str,
"\xDF",
"ss");
103 str =
replace(str,
"\xC9",
"E");
104 str =
replace(str,
"\xE9",
"e");
105 str =
replace(str,
"\xC8",
"E");
106 str =
replace(str,
"\xE8",
"e");
115 const std::string what_tmp(what);
116 const std::string by_tmp(by);
117 size_t idx = str.find(what);
118 const size_t what_len = what_tmp.length();
120 const size_t by_len = by_tmp.length();
121 while (idx != std::string::npos) {
122 str = str.replace(idx, what_len, by);
123 idx = str.find(what, idx + by_len);
132 std::ostringstream oss;
138 sprintf(buffer,
"%02i:", (time / 3600));
141 sprintf(buffer,
"%02i:", (time / 60));
144 sprintf(buffer,
"%02i", time);
152 return str.compare(0, prefix.length(), prefix) == 0;
158 if (str.length() >= suffix.length()) {
159 return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0;
168 std::string result =
replace(orig,
"&",
"&");
169 result =
replace(result,
">",
">");
170 result =
replace(result,
"<",
"<");
171 result =
replace(result,
"\"",
""");
172 for (
char invalid =
'\1'; invalid <
' '; invalid++) {
173 result =
replace(result, std::string(1, invalid).c_str(),
"");
175 return replace(result,
"'",
"'");
181 std::ostringstream out;
183 for (std::string::size_type i = 0; i < toEncode.length(); ++i) {
184 const char t = toEncode.at(i);
186 if ((encodeWhich !=
"" && encodeWhich.find(t) == std::string::npos) ||
187 (encodeWhich ==
"" &&
188 ((t >= 45 && t <= 57) ||
189 (t >= 65 && t <= 90) ||
191 (t >= 97 && t <= 122) ||
194 out << toEncode.at(i);
205 std::ostringstream out;
207 for (std::string::size_type i = 0; i < toDecode.length(); ++i) {
208 if (toDecode.at(i) ==
'%') {
209 std::string str(toDecode.substr(i + 1, 2));
213 out << toDecode.at(i);
226 s <<
"%" << std::setw(2) << std::setfill(
'0') << std::hex << i;
236 std::istringstream in(str);
241 throw std::runtime_error(
"stream decode failure");
245 return static_cast<unsigned char>(c);
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 std::string escapeXML(const std::string &orig)
Replaces the standard escapes by their XML entities.
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 startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
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 std::string urlDecode(const std::string &encoded)
static std::string charToHex(unsigned char c)