diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-02 16:32:01 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-02 16:32:01 +0100 |
commit | d00dc2c69164d8a8850d317f2868c6f131b7f679 (patch) | |
tree | c206c5088be0ed2fa0af692f1e0bc739f66d0b0a /url.cpp |
First lib versionv1.0
Diffstat (limited to 'url.cpp')
-rw-r--r-- | url.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +#include "url.h" + +std::string urlDecode(std::string s) +{ + std::string result; + + size_t pos = 0; + while (pos < s.size()) { + char c {s[pos]}; + if (c == '+') { + result += ' '; + } else if (c == '%' && pos + 2 < s.size()) { + try { + int i = stoi(s.substr(pos + 1, 2), 0, 16); + if (i < 0 || i > 255) + return result; + + result += static_cast<char>(i); + } catch (...) { + return result; + } + + pos += 2; + } else { + result += c; + } + pos++; + } + + return result; +} + |