| 2190 | } |
| 2191 | |
| 2192 | inline 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 | |
| 2229 | inline void read_file(const std::string &path, std::string &out) { |
| 2230 | std::ifstream fs(path, std::ios_base::binary); |
no test coverage detected