MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / urlEncode

Function urlEncode

Tactility/Source/network/Url.cpp:35–55  ·  view source on GitHub ↗

Adapted from https://stackoverflow.com/a/29962178/3848666

Source from the content-addressed store, hash-verified

33
34// Adapted from https://stackoverflow.com/a/29962178/3848666
35std::string urlEncode(const std::string& input) {
36 std::string result = "";
37 const char* characters = input.c_str();
38 char hex_buffer[10];
39 size_t input_length = input.length();
40
41 for (size_t i = 0;i < input_length;i++) {
42 unsigned char c = characters[i];
43 // uncomment this if you want to encode spaces with +
44 if (c==' ') {
45 result += '+';
46 } else if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
47 result += c;
48 } else {
49 sprintf(hex_buffer, "%%%02X", c); //%% means '%' literal, %02X means at least two digits, paddable with a leading zero
50 result += hex_buffer;
51 }
52 }
53
54 return result;
55}
56
57// Adapted from https://stackoverflow.com/a/29962178/3848666
58std::string urlDecode(const std::string& input) {

Callers 1

UrlTest.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected