mirror of https://github.com/CrowCpp/Crow.git
utility: improve string_equals function.
Return early if inequality is found.
This commit is contained in:
parent
2fbf93e211
commit
9f98a66cd1
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue