MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / decode_url

Function decode_url

examples/server/httplib.h:2192–2227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2190}
2191
2192inline std::string decode_url(const std::string &s,
2193 bool convert_plus_to_space) {
2194 std::string result;
2195
2196 for (size_t i = 0; i < s.size(); i++) {
2197 if (s[i] == '%' && i + 1 < s.size()) {
2198 if (s[i + 1] == 'u') {
2199 int val = 0;
2200 if (from_hex_to_i(s, i + 2, 4, val)) {
2201 // 4 digits Unicode codes
2202 char buff[4];
2203 size_t len = to_utf8(val, buff);
2204 if (len > 0) { result.append(buff, len); }
2205 i += 5; // 'u0000'
2206 } else {
2207 result += s[i];
2208 }
2209 } else {
2210 int val = 0;
2211 if (from_hex_to_i(s, i + 1, 2, val)) {
2212 // 2 digits hex codes
2213 result += static_cast<char>(val);
2214 i += 2; // '00'
2215 } else {
2216 result += s[i];
2217 }
2218 }
2219 } else if (convert_plus_to_space && s[i] == '+') {
2220 result += ' ';
2221 } else {
2222 result += s[i];
2223 }
2224 }
2225
2226 return result;
2227}
2228
2229inline void read_file(const std::string &path, std::string &out) {
2230 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.70
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected