MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / UrlEncode

Function UrlEncode

src/platform/linux/http_util.cpp:10–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8namespace HttpUtil {
9
10std::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
28std::string UrlDecode(const std::string& s) {
29 std::string result;

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected