add comment to trim function, use it correctly and remove redundant whitespace checks in CookieParser.

This commit is contained in:
Luca Schlecker 2022-06-16 01:44:22 +02:00 committed by Farook Al-Sammarraie
parent d27b5bc1bd
commit 02bbbde8b7
2 changed files with 5 additions and 6 deletions

View File

@ -225,17 +225,15 @@ namespace crow
if (pos_equal == cookies.npos)
break;
std::string name = cookies.substr(pos, pos_equal - pos);
utility::trim(name);
name = utility::trim(name);
pos = pos_equal + 1;
while (pos < cookies.size() && cookies[pos] == ' ')
pos++;
if (pos == cookies.size())
break;
size_t pos_semicolon = cookies.find(';', pos);
std::string value = cookies.substr(pos, pos_semicolon - pos);
utility::trim(value);
value = utility::trim(value);
if (value[0] == '"' && value[value.size() - 1] == '"')
{
value = value.substr(1, value.size() - 2);
@ -247,8 +245,6 @@ namespace crow
if (pos == cookies.npos)
break;
pos++;
while (pos < cookies.size() && cookies[pos] == ' ')
pos++;
}
}

View File

@ -832,6 +832,9 @@ namespace crow
return res;
}
/// Return a copy of the given string with its
/// leading and trailing whitespaces removed.
inline static std::string trim(const std::string& v)
{
if (v.empty())