utility: improve string_equals function.

Return early if inequality is found.
This commit is contained in:
Luca Schlecker 2022-06-07 02:47:07 +02:00 committed by Farook Al-Sammarraie
parent 2fbf93e211
commit 9f98a66cd1
1 changed files with 9 additions and 5 deletions

View File

@ -788,20 +788,24 @@ namespace crow
*/
inline static bool string_equals(const std::string& l, const std::string& r, bool case_sensitive = false)
{
bool equal = true;
if (l.length() != r.length())
return false;
for (size_t i = 0; i < l.length(); i++)
{
if (case_sensitive)
equal &= (l[i] == r[i]);
{
if (l[i] != r[i])
return false;
}
else
equal &= (std::toupper(l[i]) == std::toupper(r[i]));
{
if (std::toupper(l[i]) != std::toupper(r[i]))
return false;
}
}
return equal;
return true;
}
template<typename T, typename U>