utility: add string_equals function.

It serves as a replacement for boost::iequals.
This commit is contained in:
Luca Schlecker 2022-06-06 16:17:36 +02:00 committed by Farook Al-Sammarraie
parent 58583bf1a5
commit f3dba60efd

View File

@ -5,6 +5,7 @@
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <cstring> #include <cstring>
#include <cctype>
#include <functional> #include <functional>
#include <string> #include <string>
#include <unordered_map> #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 utility
} // namespace crow } // namespace crow