Some clean-up

This commit is contained in:
Veloman Yunkan 2023-01-25 19:09:16 +04:00
parent 471c5b89f4
commit ca079a72cc
1 changed files with 4 additions and 18 deletions

View File

@ -208,17 +208,6 @@ bool isHarmlessUriChar(char c)
return false; return false;
} }
bool needsEscape(char c, bool encodeReserved)
{
if (isHarmlessUriChar(c))
return false;
if (isReservedUrlChar(c))
return encodeReserved;
return true;
}
int hexToInt(char c) { int hexToInt(char c) {
switch (c) { switch (c) {
case '0': return 0; case '0': return 0;
@ -247,14 +236,11 @@ std::string kiwix::urlEncode(const std::string& value)
{ {
std::ostringstream os; std::ostringstream os;
os << std::hex << std::uppercase; os << std::hex << std::uppercase;
for (std::string::const_iterator it = value.begin(); for (const char c : value) {
it != value.end(); if (isHarmlessUriChar(c)) {
it++) { os << c;
if (!needsEscape(*it, true)) {
os << *it;
} else { } else {
const unsigned int charVal = static_cast<unsigned char>(*it); const unsigned int charVal = static_cast<unsigned char>(c);
os << '%' << std::setw(2) << std::setfill('0') << charVal; os << '%' << std::setw(2) << std::setfill('0') << charVal;
} }
} }