2022-03-29 16:50:26 -04:00
|
|
|
|
|
|
|
|
#include "wrap-sstream.hpp"
|
|
|
|
|
#include "wrap-string.hpp"
|
|
|
|
|
|
|
|
|
|
static eng::string url_encode(const eng::string &value) {
|
|
|
|
|
eng::ostringstream escaped;
|
|
|
|
|
escaped.fill('0');
|
|
|
|
|
escaped << hex;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < int(value.size()); i++) {
|
|
|
|
|
char c = value[i];
|
|
|
|
|
|
|
|
|
|
// Keep alphanumeric and other accepted characters intact
|
|
|
|
|
// Any other characters are percent-encoded
|
|
|
|
|
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
|
|
|
|
|
escaped << c;
|
|
|
|
|
} else {
|
|
|
|
|
escaped << std::uppercase;
|
|
|
|
|
escaped << '%' << std::setw(2) << int((unsigned char) c);
|
|
|
|
|
escaped << std::nouppercase;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return escaped.str();
|
|
|
|
|
}
|
|
|
|
|
|