URL-encode src and append to dst. */
| 35 | |
| 36 | /** URL-encode src and append to dst. */ |
| 37 | static std::string pni_urlencode(const std::string &src) { |
| 38 | static const char *bad = "@:/%[]?#"; |
| 39 | |
| 40 | std::ostringstream dst; |
| 41 | dst << std::hex << std::uppercase << std::setfill('0'); |
| 42 | |
| 43 | std::size_t i = 0; |
| 44 | std::size_t j = src.find_first_of(bad); |
| 45 | while (j!=std::string::npos) { |
| 46 | dst << src.substr(i, j-i); |
| 47 | dst << "%" << std::setw(2) << int(src[j]); |
| 48 | i = j + 1; |
| 49 | j = src.find_first_of(bad, i); |
| 50 | } |
| 51 | dst << src.substr(i); |
| 52 | return dst.str(); |
| 53 | } |
| 54 | |
| 55 | // Low level url parser |
| 56 | static void pni_urldecode(const char *src, char *dst) |