29 #define urlencode __urlencode 30 inline std::string __urlencode(
const std::string& str) {
32 out.reserve(2 * str.length());
33 const char* cstr = str.c_str();
36 if (isalnum(*cstr) || *cstr ==
'-' || *cstr ==
'_' || *cstr ==
'.' || *cstr ==
'~')
40 sprintf(buf,
"%%%.2x", static_cast<unsigned char>(*cstr));
48 #define urldecode __urldecode 49 inline std::string __urldecode(
const std::string& str) {
51 out.reserve(str.length());
52 const char* cstr = str.c_str();
60 strncpy(buf, cstr + 1, 3);
62 if (sscanf(buf,
"%x", &v) == 1 || sscanf(buf,
"%X", &v) == 1)
64 c =
static_cast<char>(v);