MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / decode_url

Function decode_url

dependencies/httplib/httplib.h:2070–2105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2068}
2069
2070inline std::string decode_url(const std::string &s,
2071 bool convert_plus_to_space) {
2072 std::string result;
2073
2074 for (size_t i = 0; i < s.size(); i++) {
2075 if (s[i] == '%' && i + 1 < s.size()) {
2076 if (s[i + 1] == 'u') {
2077 int val = 0;
2078 if (from_hex_to_i(s, i + 2, 4, val)) {
2079 // 4 digits Unicode codes
2080 char buff[4];
2081 size_t len = to_utf8(val, buff);
2082 if (len > 0) { result.append(buff, len); }
2083 i += 5; // 'u0000'
2084 } else {
2085 result += s[i];
2086 }
2087 } else {
2088 int val = 0;
2089 if (from_hex_to_i(s, i + 1, 2, val)) {
2090 // 2 digits hex codes
2091 result += static_cast<char>(val);
2092 i += 2; // '00'
2093 } else {
2094 result += s[i];
2095 }
2096 }
2097 } else if (convert_plus_to_space && s[i] == '+') {
2098 result += ' ';
2099 } else {
2100 result += s[i];
2101 }
2102 }
2103
2104 return result;
2105}
2106
2107inline void read_file(const std::string &path, std::string &out) {
2108 std::ifstream fs(path, std::ios_base::binary);

Callers 4

parse_headerFunction · 0.85
parse_query_textFunction · 0.85
parse_request_lineMethod · 0.85
redirectMethod · 0.85

Calls 4

from_hex_to_iFunction · 0.85
to_utf8Function · 0.85
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected