feat(string): add SStrChrBidir

This commit is contained in:
Adam Heinermann 2025-11-14 23:46:15 -08:00 committed by fallenoak
parent 0250f274ca
commit 5ec28d3aac
5 changed files with 93 additions and 1 deletions

View file

@ -122,6 +122,82 @@ TEST_CASE("SStrChrR const", "[string]") {
}
}
TEST_CASE("SStrChrBidir", "[string]") {
SECTION("forwards") {
const char* string = "foobar";
SECTION("finds first character when it exists at start of string") {
const char* result = SStrChrBidir(string, 'f', 0);
REQUIRE(result == string);
}
SECTION("finds first character when it exists in middle of string") {
const char* result = SStrChrBidir(string, 'b', 0);
REQUIRE(result == string + 3);
}
SECTION("finds first character when it exists at end of string") {
const char* result = SStrChrBidir(string, 'r', 0);
REQUIRE(result == string + 5);
}
SECTION("returns nullptr when character does not exist in string") {
const char* result = SStrChrBidir(string, 'z', 0);
REQUIRE(result == nullptr);
}
SECTION("returns nullptr when string is empty") {
const char* result = SStrChrBidir("", 'z', 0);
REQUIRE(result == nullptr);
}
SECTION("returns nullptr when character is 0") {
const char* result = SStrChrBidir(string, '\0', 0);
REQUIRE(result == nullptr);
}
}
SECTION("reversed") {
const char* string = "ffoobbaarr";
SECTION("finds last character when it exists at start of string") {
const char* result = SStrChrBidir(string, 'f', 1);
REQUIRE(result == string + 1);
}
SECTION("finds last character when it exists in middle of string") {
const char* result = SStrChrBidir(string, 'b', 1);
REQUIRE(result == string + 5);
}
SECTION("finds last character when it exists at end of string") {
const char* result = SStrChrBidir(string, 'r', 1);
REQUIRE(result == string + 9);
}
SECTION("finds last character when it exists at start and end of string") {
const char* string = "ffoobbaarrff";
const char* result = SStrChrBidir(string, 'f', 1);
REQUIRE(result == string + 11);
}
SECTION("returns nullptr when character does not exist in string") {
const char* result = SStrChrBidir(string, 'z', 1);
REQUIRE(result == nullptr);
}
SECTION("returns nullptr when string is empty") {
const char* result = SStrChrBidir("", 'z', 1);
REQUIRE(result == nullptr);
}
SECTION("returns nullptr when character is 0") {
const char* result = SStrChrBidir(string, '\0', 1);
REQUIRE(result == nullptr);
}
}
}
#if !defined(WHOA_TEST_STORMDLL)
TEST_CASE("SStrChrR", "[string]") {
char string[] = "ffoobbaarr";

View file

@ -322,7 +322,7 @@ EXPORTS
SStrHash @502 NONAME
SStrPack @503 NONAME
SStrTokenize @504 NONAME
;SStrChrBidir @505 NONAME
SStrChrBidir @505 NONAME
SStrLen @506 NONAME
SStrDupA @507 NONAME
SStrCmp @508 NONAME

View file

@ -90,6 +90,7 @@ void STORMAPI SRgnOffseti(HSRGN, int32_t, int32_t) {}
char* STORMAPI SStrChr(char*, char) { return 0; }
const char* STORMAPI SStrChr(const char*, char) { return 0; }
const char* STORMAPI SStrChrBidir(const char*, char, int32_t) { return 0; }
char* STORMAPI SStrChrR(char*, char) { return 0; }
const char* STORMAPI SStrChrR(const char*, char) { return 0; }
int32_t STORMAPI SStrCmp(const char*, const char*, size_t) { return 0; }