mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(string): add SStrUpper
This commit is contained in:
parent
b4485a3498
commit
0d00bd3ae4
3 changed files with 33 additions and 0 deletions
|
|
@ -629,3 +629,10 @@ int32_t SStrToInt(const char* string) {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SStrUpper(char* string) {
|
||||||
|
while (*string) {
|
||||||
|
*string = static_cast<char>(toupper(*string));
|
||||||
|
string++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,6 @@ float SStrToFloat(const char* string);
|
||||||
|
|
||||||
int32_t SStrToInt(const char* string);
|
int32_t SStrToInt(const char* string);
|
||||||
|
|
||||||
|
void SStrUpper(char* string);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -398,3 +398,27 @@ TEST_CASE("SStrToInt", "[string]") {
|
||||||
REQUIRE(result == 123);
|
REQUIRE(result == 123);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("SStrUpper", "[string]") {
|
||||||
|
SECTION("rewrites lowercase string to uppercase correctly") {
|
||||||
|
auto lower = "foobar";
|
||||||
|
auto upper = static_cast<char*>(SMemAlloc(SStrLen(lower) + 1, __FILE__, __LINE__, 0x0));
|
||||||
|
SStrCopy(upper, lower, STORM_MAX_STR);
|
||||||
|
SStrUpper(upper);
|
||||||
|
auto compare = SStrCmp(upper, "FOOBAR", SStrLen(upper));
|
||||||
|
SMemFree(upper);
|
||||||
|
|
||||||
|
REQUIRE(!compare);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("rewrites uppercase string to uppercase correctly") {
|
||||||
|
auto upper1 = "FOOBAR";
|
||||||
|
auto upper2 = static_cast<char*>(SMemAlloc(SStrLen(upper1) + 1, __FILE__, __LINE__, 0x0));
|
||||||
|
SStrCopy(upper2, upper1, STORM_MAX_STR);
|
||||||
|
SStrUpper(upper2);
|
||||||
|
auto compare = SStrCmp(upper2, "FOOBAR", SStrLen(upper2));
|
||||||
|
SMemFree(upper2);
|
||||||
|
|
||||||
|
REQUIRE(!compare);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue