| 2068 | } |
| 2069 | |
| 2070 | inline 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 | |
| 2107 | inline void read_file(const std::string &path, std::string &out) { |
| 2108 | std::ifstream fs(path, std::ios_base::binary); |
no test coverage detected