Added strutils
This commit is contained in:
@ -1,12 +1,17 @@
|
|||||||
set(headers
|
set(headers
|
||||||
include/cleanuphelper.h
|
src/cleanuphelper.h
|
||||||
include/cppflags.h
|
src/cppflags.h
|
||||||
include/cppmacros.h
|
src/cppmacros.h
|
||||||
include/cppoverloadutils.h
|
src/cppoverloadutils.h
|
||||||
include/cppsignal.h
|
src/cppsignal.h
|
||||||
include/cpptypesafeenum.h
|
src/cpptypesafeenum.h
|
||||||
include/cpputils.h
|
src/cpputils.h
|
||||||
include/delayedconstruction.h
|
src/delayedconstruction.h
|
||||||
|
src/strutils.h
|
||||||
)
|
)
|
||||||
|
|
||||||
idf_component_register(INCLUDE_DIRS include SRCS ${headers})
|
set(sources
|
||||||
|
src/strutils.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
idf_component_register(INCLUDE_DIRS src SRCS ${headers} ${sources})
|
||||||
|
37
src/strutils.cpp
Normal file
37
src/strutils.cpp
Normal 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
|
9
src/strutils.h
Normal file
9
src/strutils.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace cpputils {
|
||||||
|
bool stringEqualsIgnoreCase(std::string_view a, std::string_view b);
|
||||||
|
bool stringStartsWith(std::string_view fullString, std::string_view begin);
|
||||||
|
bool stringEndsWith(std::string_view fullString, std::string_view ending);
|
||||||
|
} // namespace cpputils
|
Reference in New Issue
Block a user