MCPcopy Create free account
hub / github.com/PABannier/bark.cpp / encode_url

Function encode_url

examples/server/httplib.h:2363–2393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2361}
2362
2363inline std::string encode_url(const std::string &s) {
2364 std::string result;
2365 result.reserve(s.size());
2366
2367 for (size_t i = 0; s[i]; i++) {
2368 switch (s[i]) {
2369 case ' ': result += "%20"; break;
2370 case '+': result += "%2B"; break;
2371 case '\r': result += "%0D"; break;
2372 case '\n': result += "%0A"; break;
2373 case '\'': result += "%27"; break;
2374 case ',': result += "%2C"; break;
2375 // case ':': result += "%3A"; break; // ok? probably...
2376 case ';': result += "%3B"; break;
2377 default:
2378 auto c = static_cast<uint8_t>(s[i]);
2379 if (c >= 0x80) {
2380 result += '%';
2381 char hex[4];
2382 auto len = snprintf(hex, sizeof(hex) - 1, "%02X", c);
2383 assert(len == 2);
2384 result.append(hex, static_cast<size_t>(len));
2385 } else {
2386 result += s[i];
2387 }
2388 break;
2389 }
2390 }
2391
2392 return result;
2393}
2394
2395inline std::string decode_url(const std::string &s,
2396 bool convert_plus_to_space) {

Callers 1

write_requestMethod · 0.85

Calls 2

appendMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected