diff options
Diffstat (limited to 'src/zencore')
| -rw-r--r-- | src/zencore/include/zencore/string.h | 18 | ||||
| -rw-r--r-- | src/zencore/string.cpp | 11 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/zencore/include/zencore/string.h b/src/zencore/include/zencore/string.h index 4deca63ed..5a8a66fae 100644 --- a/src/zencore/include/zencore/string.h +++ b/src/zencore/include/zencore/string.h @@ -953,6 +953,24 @@ StrCaseCompare(const char* Lhs, const char* Rhs, int64_t Length = -1) #endif } +inline int32_t +StrCaseCompare(std::string_view Lhs, std::string_view Rhs) +{ + int32_t Result = StrCaseCompare(Lhs.data(), Rhs.data(), std::min(Lhs.size(), Rhs.size())); + if (Result == 0) + { + if (Lhs.size() < Rhs.size()) + { + return -1; + } + else if (Lhs.size() > Rhs.size()) + { + return 1; + } + } + return Result; +} + /** * @brief * Helper function to implement case sensitive spaceship operator for strings. diff --git a/src/zencore/string.cpp b/src/zencore/string.cpp index ed0ba6f46..358722b0b 100644 --- a/src/zencore/string.cpp +++ b/src/zencore/string.cpp @@ -1181,6 +1181,17 @@ TEST_CASE("string") CHECK(StrCaseCompare("BBr", "Bar", 2) > 0); } + SUBCASE("StrCaseCompare") + { + CHECK(StrCaseCompare("foo"sv, "FoO"sv) == 0); + CHECK(StrCaseCompare("foo"sv, "FoOz"sv) < 0); + CHECK(StrCaseCompare("fooo"sv, "FoO"sv) > 0); + CHECK(StrCaseCompare("Bar"sv, "bAs"sv) < 0); + CHECK(StrCaseCompare("bAr"sv, "Bas"sv) < 0); + CHECK(StrCaseCompare("BBr"sv, "Bar"sv) > 0); + CHECK(StrCaseCompare("Bbr"sv, "BAr"sv) > 0); + } + SUBCASE("ForEachStrTok") { const auto Tokens = "here,is,my,different,tokens"sv; |