static
| 228 | |
| 229 | // static |
| 230 | std::string http_client::urlencode(const std::string& in, bool post_encode) |
| 231 | { |
| 232 | static std::string allowed_chars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"); |
| 233 | |
| 234 | std::stringstream ss; |
| 235 | ss << std::hex; |
| 236 | for (std::string::const_iterator ci = in.begin(); ci != in.end(); ++ci) |
| 237 | { |
| 238 | if ( allowed_chars.find(*ci) != std::string::npos ) |
| 239 | { |
| 240 | ss << *ci; |
| 241 | } |
| 242 | else if ( post_encode && *ci == ' ' ) |
| 243 | { |
| 244 | ss << '+'; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | ss << '%' << std::setfill('0') << std::setw(2) << std::right << static_cast<int>(*ci); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | return ss.str(); |
| 253 | } |
| 254 | |
| 255 | // ---------------------------------------------------------------------------------------- |
| 256 |