| 51 | static std::function<bool (char)> ShouldNotEscape = boost::is_any_of("-_.~"); // NOLINT(*) |
| 52 | |
| 53 | static inline void UrlEncode(const char* in, int in_len, string* out, bool hive_compat) { |
| 54 | (*out).reserve(in_len); |
| 55 | std::ostringstream ss; |
| 56 | for (int i = 0; i < in_len; ++i) { |
| 57 | const char ch = in[i]; |
| 58 | // Escape the character iff a) we are in Hive-compat mode and the |
| 59 | // character is in the Hive whitelist or b) we are not in |
| 60 | // Hive-compat mode, and the character is not alphanumeric or one |
| 61 | // of the four commonly excluded characters. |
| 62 | if ((hive_compat && HiveShouldEscape(ch)) || |
| 63 | (!hive_compat && !(isalnum(ch) || ShouldNotEscape(ch)))) { |
| 64 | ss << '%' << std::uppercase << std::hex << static_cast<uint32_t>(ch); |
| 65 | } else { |
| 66 | ss << ch; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | (*out) = ss.str(); |
| 71 | } |
| 72 | |
| 73 | void UrlEncode(const vector<uint8_t>& in, string* out, bool hive_compat) { |
| 74 | if (in.empty()) { |