r_string: combine equality operation algorithm.

A private templated function containing the algorithm is used to prevent repetition.
This commit is contained in:
Luca Schlecker 2022-06-08 15:47:13 +02:00 committed by Farook Al-Sammarraie
parent a977c87fef
commit e7a04859fe
1 changed files with 22 additions and 30 deletions

View File

@ -183,6 +183,25 @@ namespace crow
owned_ = 1;
}
friend rvalue crow::json::load(const char* data, size_t size);
friend bool operator==(const r_string& l, const r_string& r);
friend bool operator==(const std::string& l, const r_string& r);
friend bool operator==(const r_string& l, const std::string& r);
template<typename T, typename U>
inline static bool equals(const T& l, const U& r)
{
if (l.size() != r.size())
return false;
for (size_t i = 0; i < l.size(); i++)
{
if (*(l.begin() + i) != *(r.begin() + i))
return false;
}
return true;
}
};
inline bool operator<(const r_string& l, const r_string& r)
@ -217,44 +236,17 @@ namespace crow
inline bool operator==(const r_string& l, const r_string& r)
{
if (l.size() != r.size())
return false;
for (size_t i = 0; i < l.size(); i++)
{
if (*(l.begin() + i) != *(r.begin() + i))
return false;
}
return true;
return r_string::equals(l, r);
}
inline bool operator==(const r_string& l, const std::string& r)
{
if (l.size() != r.size())
return false;
for (size_t i = 0; i < l.size(); i++)
{
if (*(l.begin() + i) != *(r.begin() + i))
return false;
}
return true;
return r_string::equals(l, r);
}
inline bool operator==(const std::string& l, const r_string& r)
{
if (l.size() != r.size())
return false;
for (size_t i = 0; i < l.size(); i++)
{
if (*(l.begin() + i) != *(r.begin() + i))
return false;
}
return true;
return r_string::equals(l, r);
}
inline bool operator!=(const r_string& l, const r_string& r)