chore(str): kill gotos in SStrTokenize (#42)

This commit is contained in:
Adam Heinermann 2025-04-20 07:15:32 -07:00 committed by GitHub
parent aaa44dd400
commit 0854138653
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 70 additions and 50 deletions

View file

@ -291,6 +291,48 @@ TEST_CASE("SStrTokenize", "[string]") {
SStrTokenize(&string, buffer, 1000, " ,", nullptr);
REQUIRE(!SStrCmp(buffer, "", STORM_MAX_STR));
}
SECTION("identifies quoted tokens") {
auto string = "foo bar \"baz bazinga\" bodonkers \"donga dongs\"";
char buffer[100] = { 0 };
std::pair<const char*, int> tokens[] = {
std::make_pair("foo", 0),
std::make_pair("bar", 0),
std::make_pair("baz bazinga", 1),
std::make_pair("bodonkers", 0),
std::make_pair("donga dongs", 1)
};
for (auto& token : tokens) {
int quoted = 0;
SStrTokenize(&string, buffer, 1000, " \"", &quoted);
std::string result = buffer;
REQUIRE(result == token.first);
REQUIRE(quoted == token.second);
}
}
SECTION("doesn't identify quoted tokens if excluded from whitespace") {
auto string = "foo bar \"baz bazinga\" bodonkers \"donga dongs\"";
char buffer[100] = { 0 };
std::pair<const char*, int> tokens[] = {
std::make_pair("foo", 0),
std::make_pair("bar", 0),
std::make_pair("\"baz", 0),
std::make_pair("bazinga\"", 0),
std::make_pair("bodonkers", 0),
std::make_pair("\"donga", 0),
std::make_pair("dongs\"", 0)
};
for (auto& token : tokens) {
int quoted = 0;
SStrTokenize(&string, buffer, 1000, " ", &quoted);
std::string result = buffer;
REQUIRE(result == token.first);
REQUIRE(quoted == token.second);
}
}
}
TEST_CASE("SStrToFloat", "[string]") {