| 119 | } |
| 120 | |
| 121 | void PercentEncode(const std::string& str, std::string* str_out) { |
| 122 | std::ostringstream escaped; |
| 123 | escaped.fill('0'); |
| 124 | escaped << std::hex; |
| 125 | for (std::string::const_iterator it = str.begin(); |
| 126 | it != str.end(); ++it) { |
| 127 | const std::string::value_type& c = *it; |
| 128 | // Unreserved Characters are referred from |
| 129 | // https://en.wikipedia.org/wiki/Percent-encoding |
| 130 | if ((c >= 'a' && c <= 'z') || |
| 131 | (c >= 'A' && c <= 'Z') || |
| 132 | c == '-' || c == '_' || c == '.' || c == '~') { |
| 133 | escaped << c; |
| 134 | continue; |
| 135 | } |
| 136 | escaped << '%' << std::setw(2) << int((unsigned char) c); |
| 137 | } |
| 138 | if (str_out) { |
| 139 | *str_out = escaped.str(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | static int hex_to_int(char c) { |
| 144 | if (c >= 'a' && c <= 'f') { |