This commit is contained in:
keita
2022-04-23 20:57:59 +09:00
parent 9f2c61b7e0
commit 1a1ccdca27
12 changed files with 30 additions and 42 deletions
+4 -6
View File
@@ -22,27 +22,25 @@ std::string urlEncode(const std::string& _str) {
return out.str();
}
std::string urlDecode(const std::string& _str){
std::string urlDecode(const std::string& _str) {
std::stringstream out;
int first = 0;
int last = _str.find_first_of('%');
while (first < _str.size()) {
if (last == std::string::npos) {
out << _str.substr(first);
break;
}
auto s = _str.substr(first, last - first);
auto encoded = _str.substr(last+1, 2); // %を飛ばし読みする
auto s = _str.substr(first, last - first);
auto encoded = _str.substr(last + 1, 2); // %を飛ばし読みする
std::cout << encoded << std::endl;
auto c = static_cast<char>(static_cast<int>(strtol(encoded.c_str(), nullptr, 16)));
out << s << c;
first = last + 3;
last = _str.find_first_of('%', first);
}