MCPcopy Create free account
hub / github.com/SIPp/sipp / url_encode

Function url_encode

src/urlcoder.cpp:23–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#include <cstring>
22
23std::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
49std::string url_decode(std::string str) {
50 std::string ret;

Callers 2

TESTFunction · 0.85
executeActionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected