Added strutils

This commit is contained in:
2021-02-09 18:35:08 +01:00
parent 8114e9b1b3
commit f623ffd842
11 changed files with 60 additions and 9 deletions

37
src/strutils.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "strutils.h"
// system includes
#include <algorithm>
#include <cctype>
namespace cpputils {
bool stringEqualsIgnoreCase(std::string_view a, std::string_view b)
{
return a == b; // HACK for now...
if (a.size() != b.size())
return false;
return std::equal(std::begin(a), std::end(a), std::begin(b),
[](char a, char b) {
return std::tolower(a) == std::tolower(b);
});
}
bool stringStartsWith(std::string_view fullString, std::string_view begin)
{
return fullString.rfind(begin, 0) == 0;
}
bool stringEndsWith(std::string_view fullString, std::string_view ending)
{
if (fullString.length() >= ending.length())
{
return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
}
else
{
return false;
}
}
} // namespace cpputils