mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
fix(string): correctly handle not found case in SStrStr
This commit is contained in:
parent
001edb9a7a
commit
611186db9e
2 changed files with 19 additions and 1 deletions
|
|
@ -234,8 +234,12 @@ const char* SStrStr(const char* string, const char* search) {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
while (*substring && SStrCmp(substring, search, length)) {
|
||||
while (SStrCmp(substring, search, length)) {
|
||||
substring++;
|
||||
|
||||
if (!*substring) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return substring;
|
||||
|
|
|
|||
|
|
@ -91,6 +91,20 @@ TEST_CASE("SStrStr", "[string]") {
|
|||
REQUIRE(!SStrCmp(search, substring, SStrLen(search)));
|
||||
}
|
||||
|
||||
SECTION("finds substring when search is empty") {
|
||||
auto string = "foobar";
|
||||
auto search = "";
|
||||
auto substring = SStrStr(string, search);
|
||||
REQUIRE(!SStrCmp(string, substring, SStrLen(string)));
|
||||
}
|
||||
|
||||
SECTION("returns nullptr when search does not exist in string") {
|
||||
auto string = "foobar";
|
||||
auto search = "xyzzy";
|
||||
auto substring = SStrStr(string, search);
|
||||
REQUIRE(substring == nullptr);
|
||||
}
|
||||
|
||||
SECTION("returns nullptr when given empty string") {
|
||||
auto string = "";
|
||||
auto search = "bar";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue