diff --git a/storm/String.cpp b/storm/String.cpp index 1471f4e..becc2fb 100644 --- a/storm/String.cpp +++ b/storm/String.cpp @@ -2,6 +2,7 @@ #include "storm/Error.hpp" #include "storm/string/bjhash.hpp" #include +#include uint8_t bytesFromUTF8[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -133,6 +134,10 @@ int32_t SStrCmp(const char* string1, const char* string2, size_t maxchars) { return strncmp(string1, string2, maxchars); } +int32_t SStrCmpI(const char* string1, const char* string2, size_t maxchars) { + return strncasecmp(string1, string2, maxchars); +} + size_t SStrCopy(char* dest, const char* source, size_t destsize) { STORM_ASSERT(dest); STORM_ASSERT(source); diff --git a/storm/String.hpp b/storm/String.hpp index 6e07c41..285c7ef 100644 --- a/storm/String.hpp +++ b/storm/String.hpp @@ -9,6 +9,8 @@ int32_t SStrCmp(const char* string1, const char* string2, size_t maxchars); +int32_t SStrCmpI(const char* string1, const char* string2, size_t maxchars); + size_t SStrCopy(char* dest, const char* source, size_t destsize); uint32_t SStrHashHT(const char* string); diff --git a/test/String.cpp b/test/String.cpp index f159635..4afe378 100644 --- a/test/String.cpp +++ b/test/String.cpp @@ -20,6 +20,23 @@ TEST_CASE("SStrCmp", "[string]") { } } +TEST_CASE("SStrCmpI", "[string]") { + SECTION("compares two strings that exactly match correctly") { + auto compare = SStrCmpI("foo", "foo", STORM_MAX_STR); + REQUIRE(compare == 0); + } + + SECTION("compares two strings that match with differing case correctly") { + auto compare = SStrCmpI("foo", "foO", STORM_MAX_STR); + REQUIRE(compare == 0); + } + + SECTION("compares two strings that do not match correctly") { + auto compare = SStrCmpI("bar", "xyzzy", STORM_MAX_STR); + REQUIRE(compare < 0); + } +} + TEST_CASE("SStrHashHT", "[string]") { SECTION("hashes simple string correctly") { auto hash = SStrHashHT("foo");