mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-21 22:13:07 +01:00
Introduce String::URLEncode
This commit is contained in:
@@ -14,7 +14,10 @@
|
||||
#endif // __MINGW32__
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cwctype>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#ifndef _WIN32
|
||||
@@ -823,6 +826,31 @@ namespace String
|
||||
|
||||
return trunc;
|
||||
}
|
||||
|
||||
std::string URLEncode(std::string_view value)
|
||||
{
|
||||
std::ostringstream escaped;
|
||||
escaped.fill('0');
|
||||
escaped << std::hex;
|
||||
|
||||
for (auto c : value)
|
||||
{
|
||||
// Keep alphanumeric and other accepted characters intact
|
||||
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
|
||||
{
|
||||
escaped << c;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Any other characters are percent-escaped
|
||||
escaped << std::uppercase;
|
||||
escaped << '%' << std::setw(2) << int32_t(static_cast<unsigned char>(c));
|
||||
escaped << std::nouppercase;
|
||||
}
|
||||
}
|
||||
|
||||
return escaped.str();
|
||||
}
|
||||
} // namespace String
|
||||
|
||||
char32_t CodepointView::iterator::GetNextCodepoint(const char* ch, const char** next)
|
||||
|
||||
Reference in New Issue
Block a user