diff --git a/CMakeLists.txt b/CMakeLists.txt index b409ee4..d26557f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,17 @@ set(headers - include/cleanuphelper.h - include/cppflags.h - include/cppmacros.h - include/cppoverloadutils.h - include/cppsignal.h - include/cpptypesafeenum.h - include/cpputils.h - include/delayedconstruction.h + src/cleanuphelper.h + src/cppflags.h + src/cppmacros.h + src/cppoverloadutils.h + src/cppsignal.h + src/cpptypesafeenum.h + src/cpputils.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}) diff --git a/include/cleanuphelper.h b/src/cleanuphelper.h similarity index 100% rename from include/cleanuphelper.h rename to src/cleanuphelper.h diff --git a/include/cppflags.h b/src/cppflags.h similarity index 100% rename from include/cppflags.h rename to src/cppflags.h diff --git a/include/cppmacros.h b/src/cppmacros.h similarity index 100% rename from include/cppmacros.h rename to src/cppmacros.h diff --git a/include/cppoverloadutils.h b/src/cppoverloadutils.h similarity index 100% rename from include/cppoverloadutils.h rename to src/cppoverloadutils.h diff --git a/include/cppsignal.h b/src/cppsignal.h similarity index 100% rename from include/cppsignal.h rename to src/cppsignal.h diff --git a/include/cpptypesafeenum.h b/src/cpptypesafeenum.h similarity index 100% rename from include/cpptypesafeenum.h rename to src/cpptypesafeenum.h diff --git a/include/cpputils.h b/src/cpputils.h similarity index 100% rename from include/cpputils.h rename to src/cpputils.h diff --git a/include/delayedconstruction.h b/src/delayedconstruction.h similarity index 100% rename from include/delayedconstruction.h rename to src/delayedconstruction.h diff --git a/src/strutils.cpp b/src/strutils.cpp new file mode 100644 index 0000000..6e4c4e1 --- /dev/null +++ b/src/strutils.cpp @@ -0,0 +1,37 @@ +#include "strutils.h" + +// system includes +#include +#include + +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 diff --git a/src/strutils.h b/src/strutils.h new file mode 100644 index 0000000..599fa26 --- /dev/null +++ b/src/strutils.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +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