| 21 | #include <cstring> |
| 22 | |
| 23 | std::string url_encode(const std::string &str) { |
| 24 | std::string new_str; |
| 25 | unsigned char c; |
| 26 | int ic; |
| 27 | const char *chars = str.c_str(); |
| 28 | char bufHex[10]; |
| 29 | size_t len = strlen(chars); |
| 30 | |
| 31 | for (unsigned int i = 0; i < len; i++) { |
| 32 | c = chars[i]; |
| 33 | ic = c; |
| 34 | if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { |
| 35 | new_str += c; |
| 36 | } else { |
| 37 | sprintf(bufHex, "%X", c); |
| 38 | if (ic < 16) { |
| 39 | new_str += "%0"; |
| 40 | } else { |
| 41 | new_str += "%"; |
| 42 | } |
| 43 | new_str += bufHex; |
| 44 | } |
| 45 | } |
| 46 | return new_str; |
| 47 | } |
| 48 | |
| 49 | std::string url_decode(std::string str) { |
| 50 | std::string ret; |
no outgoing calls
no test coverage detected