diff options
author | Oleg Morozenkov <reo7sp@users.noreply.github.com> | 2017-01-14 12:54:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-14 12:54:58 +0300 |
commit | f986328344e1e5a1c7fad3a529f27bb85aed0c83 (patch) | |
tree | eae827328055dde732bd8fff66500c1bf0051aac /src/tools | |
parent | 429dd74b583e0ac52d50142be493cba532ca017d (diff) | |
parent | 19a83123e908e8d80b404d47ec843fa6f0d4a5a6 (diff) |
Merge pull request #32 from kukin-konstantin/master
ReplyKeyboardMarkup and UTF-8
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/StringTools.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index c682b35..d5270db 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -84,20 +84,22 @@ string generateRandomString(size_t length) { 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; + static const string legitPunctuation = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~:"; + std::stringstream ss; + std::string t; + for (auto const &c : value) { + if ((legitPunctuation.find(c) == std::string::npos) + && (additionalLegitChars.find(c)==std::string::npos)) { + ss << '%' << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)(unsigned char)c; + t = ss.str(); } else { - result << '%' << setw(2) << int((unsigned char) c); + ss << c; } } - return result.str(); + return ss.str(); } string urlDecode(const string& value) { |