diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-08-11 22:13:23 +0300 |
---|---|---|
committer | Oleg Morozenkov <omorozenkov@gmail.com> | 2015-08-11 22:13:23 +0300 |
commit | 376b88ec09ef8cf71dd823467406c58204485fcc (patch) | |
tree | 9ca599b854d18006c65b26003ce7dbdd416fdf18 /src/tools/StringTools.cpp | |
parent | d7fbf7149d0e0c1c30972dab68d510ef6ac377dd (diff) |
Fixed compiler's errors in TgTypeParser + fixed indentation + some other fixes
Diffstat (limited to 'src/tools/StringTools.cpp')
-rw-r--r-- | src/tools/StringTools.cpp | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index deb8fa1..0a6dbc3 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -35,17 +35,17 @@ bool startsWith(const string& str1, const string& str2) { return false; } string::const_iterator it1(str1.begin()); - string::const_iterator end1(str1.end()); - string::const_iterator it2(str2.begin()); - string::const_iterator end2(str2.end()); - while (it1 != end1 && it2 != end2) { - if (*it1 != *it2) { - return false; - } - ++it1; - ++it2; - } - return true; + string::const_iterator end1(str1.end()); + string::const_iterator it2(str2.begin()); + string::const_iterator end2(str2.end()); + while (it1 != end1 && it2 != end2) { + if (*it1 != *it2) { + return false; + } + ++it1; + ++it2; + } + return true; } bool endsWith(const string& str1, const string& str2) { @@ -53,67 +53,67 @@ bool endsWith(const string& str1, const string& str2) { return false; } string::const_iterator it1(str1.end()); - string::const_iterator begin1(str1.begin()); - string::const_iterator it2(str2.end()); - string::const_iterator begin2(str2.begin()); - while (it1 != begin1 && it2 != begin2) { - if (*it1 != *it2) { - return false; - } - --it1; - --it2; - } - return true; + string::const_iterator begin1(str1.begin()); + string::const_iterator it2(str2.end()); + string::const_iterator begin2(str2.begin()); + while (it1 != begin1 && it2 != begin2) { + if (*it1 != *it2) { + return false; + } + --it1; + --it2; + } + return true; } void split(const string& str, char delimiter, vector<string>& dest) { - istringstream stream(str); - string s; - while (getline(stream, s, delimiter)) { - dest.push_back(s); - } + istringstream stream(str); + string s; + while (getline(stream, s, delimiter)) { + dest.push_back(s); + } } string generateRandomString(size_t length) { - static const string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-=[]\\;',./!@#$%^&*()_+{}|:\"<>?`~"); - static const size_t charsLen = chars.length(); - string result; - for (int i = 0; i < length; ++i) { - result += chars[rand() % charsLen]; - } - return result; + static const string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-=[]\\;',./!@#$%^&*()_+{}|:\"<>?`~"); + static const size_t charsLen = chars.length(); + string result; + for (int i = 0; i < length; ++i) { + result += chars[rand() % charsLen]; + } + return result; } string urlEncode(const string& value, const std::string additionalLegitChars) { - static const string legitPunctuation = "-_.~"; - ostringstream result; - result.fill('0'); - result << hex; - for (const char& c : value) { - if (isalnum(c) || legitPunctuation.find(c) != legitPunctuation.npos || additionalLegitChars.find(c) != additionalLegitChars.npos) { - result << c; - } else { - result << '%' << setw(2) << int((unsigned char) c); - } - } + static const string legitPunctuation = "-_.~"; + ostringstream result; + result.fill('0'); + result << hex; + for (const char& c : value) { + if (isalnum(c) || legitPunctuation.find(c) != legitPunctuation.npos || additionalLegitChars.find(c) != additionalLegitChars.npos) { + result << c; + } else { + result << '%' << setw(2) << int((unsigned char) c); + } + } - return result.str(); + return result.str(); } string urlDecode(const string& value) { - string result; - for (size_t i = 0, count = value.length(); i < count; ++i) { - const char c = value[i]; - if (c == '%') { - int t = 0; - sscanf(value.substr(i + 1, 2).c_str(), "%x", &t); - result += (char) t; - i += 2; - } else { - result += c; - } - } - return result; + string result; + for (size_t i = 0, count = value.length(); i < count; ++i) { + const char c = value[i]; + if (c == '%') { + int t = 0; + sscanf(value.substr(i + 1, 2).c_str(), "%x", &t); + result += (char) t; + i += 2; + } else { + result += c; + } + } + return result; } } |