| 8 | namespace HttpUtil { |
| 9 | |
| 10 | std::string UrlEncode(const std::string& s, bool preserveSlash) { |
| 11 | std::string result; |
| 12 | result.reserve(s.size() * 1.2); |
| 13 | for (unsigned char c : s) { |
| 14 | if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || |
| 15 | c == '-' || c == '_' || c == '.' || c == '~') { |
| 16 | result += (char)c; |
| 17 | } else if (preserveSlash && c == '/') { |
| 18 | result += '/'; |
| 19 | } else { |
| 20 | char hex[4]; |
| 21 | snprintf(hex, sizeof(hex), "%%%02X", c); |
| 22 | result += hex; |
| 23 | } |
| 24 | } |
| 25 | return result; |
| 26 | } |
| 27 | |
| 28 | std::string UrlDecode(const std::string& s) { |
| 29 | std::string result; |