mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
utility: add string_equals function.
It serves as a replacement for boost::iequals.
This commit is contained in:
parent
58583bf1a5
commit
f3dba60efd
@ -5,6 +5,7 @@
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@ -780,5 +781,27 @@ namespace crow
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks two string for equality.
|
||||
* Always returns false if strings differ in size.
|
||||
* Defaults to case-insensitive comparison.
|
||||
*/
|
||||
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]);
|
||||
else
|
||||
equal &= (std::toupper(l[i]) == std::toupper(r[i]));
|
||||
}
|
||||
|
||||
return equal;
|
||||
}
|
||||
} // namespace utility
|
||||
} // namespace crow
|
||||
|
Loading…
Reference in New Issue
Block a user