Skip to content

Commit

Permalink
Optimize StringUtil::url_encode().
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Nov 23, 2024
1 parent 14ac26c commit e754df7
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/util/StringUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ std::string StringUtil::url_encode(const std::string& str)

while (cur < end)
{
if (*cur == ' ')
res += '+';
else if (isalnum(*cur) || *cur == '-' || *cur == '_' || *cur == '.' ||
*cur == '!' || *cur == '~' || *cur == '*' || *cur == '\'' ||
*cur == '(' || *cur == ')' || *cur == ':' || *cur == '/' ||
*cur == '@' || *cur == '?' || *cur == '#' || *cur == '&')
if (isalnum(*cur) || *cur == '-' || *cur == '_' || *cur == '.' ||
*cur == '!' || *cur == '~' || *cur == '*' || *cur == '\'' ||
*cur == '(' || *cur == ')' || *cur == ':' || *cur == '/' ||
*cur == '@' || *cur == '?' || *cur == '#' || *cur == '&')
{
res += *cur;
}
else if (*cur == ' ')
{
res += '+';
}
else
{
res += '%';
Expand All @@ -120,12 +124,16 @@ std::string StringUtil::url_encode_component(const std::string& str)

while (cur < end)
{
if (*cur == ' ')
res += '+';
else if (isalnum(*cur) || *cur == '-' || *cur == '_' || *cur == '.' ||
*cur == '!' || *cur == '~' || *cur == '*' || *cur == '\'' ||
*cur == '(' || *cur == ')')
if (isalnum(*cur) || *cur == '-' || *cur == '_' || *cur == '.' ||
*cur == '!' || *cur == '~' || *cur == '*' || *cur == '\'' ||
*cur == '(' || *cur == ')')
{
res += *cur;
}
else if (*cur == ' ')
{
res += '+';
}
else
{
res += '%';
Expand Down

0 comments on commit e754df7

Please sign in to comment.