From d00dc2c69164d8a8850d317f2868c6f131b7f679 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 2 Jan 2023 16:32:01 +0100 Subject: First lib version --- url.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 url.cpp (limited to 'url.cpp') diff --git a/url.cpp b/url.cpp new file mode 100644 index 0000000..5baf603 --- /dev/null +++ b/url.cpp @@ -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(i); + } catch (...) { + return result; + } + + pos += 2; + } else { + result += c; + } + pos++; + } + + return result; +} + -- cgit v1.2.3