Skip to content

Commit

Permalink
utility: improve string_equals function.
Browse files Browse the repository at this point in the history
Return early if inequality is found.
  • Loading branch information
luca-schlecker committed Jun 7, 2022
1 parent f5f8fd8 commit cb65082
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions include/crow/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit cb65082

Please sign in to comment.