| 96 | } |
| 97 | |
| 98 | std::string urlencode(const std::string& str) { |
| 99 | std::string encoded; |
| 100 | encoded.reserve(str.size() * 3); |
| 101 | for (uint8_t c : str) { |
| 102 | if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') |
| 103 | encoded += c; |
| 104 | else if (c == ' ') |
| 105 | encoded += '+'; |
| 106 | else { |
| 107 | encoded += '%'; |
| 108 | encoded += to_hex(c >> 4); |
| 109 | encoded += to_hex(c & 15); |
| 110 | } |
| 111 | } |
| 112 | encoded.shrink_to_fit(); |
| 113 | return encoded; |
| 114 | } |
| 115 | |
| 116 | void urldecode(std::string& str) { |
| 117 | size_t idxIn{0}; |