Aws::String StringUtils::URLDecode(const char* safe) { Aws::StringStream unescaped; unescaped.fill('0'); unescaped << std::hex; size_t safeLength = strlen(safe); for (auto i = safe, n = safe + safeLength; i != n; ++i) { char c = *i; if(c == '%') { char hex[3]; hex[0] = *(i + 1); hex[1] = *(i + 2); hex[2] = 0; i += 2; int hexAsInteger = strtol(hex, nullptr, 16); unescaped << (char)hexAsInteger; } else { unescaped << *i; } } return unescaped.str(); }
Aws::String StringUtils::URLEncode(const char* unsafe) { Aws::StringStream escaped; escaped.fill('0'); escaped << std::hex << std::uppercase; size_t unsafeLength = strlen(unsafe); for (auto i = unsafe, n = unsafe + unsafeLength; i != n; ++i) { char c = *i; if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { escaped << c; } else { escaped << '%' << std::setw(2) << ((int) c) << std::setw(0); } } return escaped.str(); }