1
0

Refactored to put URL Encoding / Decoding in a single place. (#3491)

This commit is contained in:
Mattes D
2016-12-25 18:29:21 +01:00
committed by GitHub
parent efc7fed05b
commit b3b723b453
7 changed files with 297 additions and 106 deletions

View File

@@ -602,30 +602,7 @@ AString cWebAdmin::GetHTMLEscapedString(const AString & a_Input)
AString cWebAdmin::GetURLEncodedString(const AString & a_Input)
{
// Translation table from nibble to hex:
static const char Hex[] = "0123456789abcdef";
// Preallocate the output to match input:
AString dst;
size_t len = a_Input.length();
dst.reserve(len);
// Loop over input and substitute whatever is needed:
for (size_t i = 0; i < len; i++)
{
char ch = a_Input[i];
if (isalnum(ch) || (ch == '-') || (ch == '_') || (ch == '.') || (ch == '~'))
{
dst.push_back(ch);
}
else
{
dst.push_back('%');
dst.push_back(Hex[(ch >> 4) & 0x0f]);
dst.push_back(Hex[ch & 0x0f]);
}
} // for i - a_Input[]
return dst;
return URLEncode(a_Input);
}