You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lokinet/llarp/util/str.cpp

64 lines
1.2 KiB
C++

#include <util/str.hpp>
6 years ago
#include <algorithm>
5 years ago
#include <cctype>
6 years ago
#include <cstring>
#include <string>
#include <set>
6 years ago
namespace llarp
{
5 years ago
bool
CaselessLessThan::operator()(string_view lhs, string_view rhs) const
{
const size_t s = std::min(lhs.size(), rhs.size());
for(size_t i = 0; i < s; ++i)
{
auto l = std::tolower(lhs[i]);
auto r = std::tolower(rhs[i]);
if(l < r)
{
return true;
}
if(l > r)
{
return false;
}
}
return lhs.size() < rhs.size();
}
bool
IsFalseValue(string_view str)
{
static const std::set< string_view, CaselessLessThan > vals{"no", "false",
"0", "off"};
return vals.count(str) > 0;
6 years ago
}
bool
IsTrueValue(string_view str)
6 years ago
{
static const std::set< string_view, CaselessLessThan > vals{"yes", "true",
"1", "on"};
return vals.count(str) > 0;
6 years ago
}
bool
StrEq(const char* s1, const char* s2)
{
size_t sz1 = strlen(s1);
size_t sz2 = strlen(s2);
if(sz1 == sz2)
{
return strncmp(s1, s2, sz1) == 0;
}
return false;
6 years ago
}
} // namespace llarp