diff options
author | jellybrick <shlee1503@naver.com> | 2020-03-14 23:21:30 +0900 |
---|---|---|
committer | jellybrick <shlee1503@naver.com> | 2020-03-14 23:21:42 +0900 |
commit | 64174491dac84c559db5c48ed850177fa3eb4da0 (patch) | |
tree | 5f7a754d57c2a7ec439f309df5e4b8d964d0834f /src/tools/StringTools.cpp | |
parent | 19f49b7a2f540a756ed9759b0fa5fb52bf73f20e (diff) |
Fix #127, #128 & Code quality improvements
It seems that the author of this code misunderstood 'Array of PollOption' as 'PollOption'.
Diffstat (limited to 'src/tools/StringTools.cpp')
-rw-r--r-- | src/tools/StringTools.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index 1246c50..f49a78e 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -3,6 +3,7 @@ #include <cstdlib> #include <iomanip> #include <cstdio> +#include <random> using namespace std; @@ -58,8 +59,13 @@ string generateRandomString(std::size_t length) { static const string chars("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-=[]\\;',./!@#$%^&*()_+{}|:\"<>?`~"); static const std::size_t charsLen = chars.length(); string result; + + random_device randomDevice; + mt19937 randomSeed(randomDevice()); + uniform_int_distribution<int> generator(0, charsLen - 1); + for (std::size_t i = 0; i < length; ++i) { - result += chars[rand() % charsLen]; + result += chars[generator(randomSeed)]; } return result; } @@ -84,8 +90,7 @@ string urlDecode(const string& value) { for (std::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); + int t = stoi(value.substr(i + 1, 2), nullptr, 16); result += (char) t; i += 2; } else { |