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

Function encode_url

dependencies/httplib/httplib.h:2038–2068  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2036}
2037
2038inline std::string encode_url(const std::string &s) {
2039 std::string result;
2040 result.reserve(s.size());
2041
2042 for (size_t i = 0; s[i]; i++) {
2043 switch (s[i]) {
2044 case ' ': result += "%20"; break;
2045 case '+': result += "%2B"; break;
2046 case '\r': result += "%0D"; break;
2047 case '\n': result += "%0A"; break;
2048 case '\'': result += "%27"; break;
2049 case ',': result += "%2C"; break;
2050 // case ':': result += "%3A"; break; // ok? probably...
2051 case ';': result += "%3B"; break;
2052 default:
2053 auto c = static_cast<uint8_t>(s[i]);
2054 if (c >= 0x80) {
2055 result += '%';
2056 char hex[4];
2057 auto len = snprintf(hex, sizeof(hex) - 1, "%02X", c);
2058 assert(len == 2);
2059 result.append(hex, static_cast<size_t>(len));
2060 } else {
2061 result += s[i];
2062 }
2063 break;
2064 }
2065 }
2066
2067 return result;
2068}
2069
2070inline std::string decode_url(const std::string &s,
2071 bool convert_plus_to_space) {

Callers 1

write_requestMethod · 0.85

Calls 3

snprintfFunction · 0.85
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected