mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(string): add SStrCmpI
This commit is contained in:
parent
0d07d79ed0
commit
7aa414f95a
3 changed files with 24 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include "storm/Error.hpp"
|
||||
#include "storm/string/bjhash.hpp"
|
||||
#include <cstring>
|
||||
#include <strings.h>
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue