diff --git a/storm/String.cpp b/storm/String.cpp index dcda5e7..de40ef3 100644 --- a/storm/String.cpp +++ b/storm/String.cpp @@ -629,3 +629,10 @@ int32_t SStrToInt(const char* string) { return result; } + +void SStrUpper(char* string) { + while (*string) { + *string = static_cast(toupper(*string)); + string++; + } +} diff --git a/storm/String.hpp b/storm/String.hpp index 98d9a72..6aa644e 100644 --- a/storm/String.hpp +++ b/storm/String.hpp @@ -37,4 +37,6 @@ float SStrToFloat(const char* string); int32_t SStrToInt(const char* string); +void SStrUpper(char* string); + #endif diff --git a/test/String.cpp b/test/String.cpp index f59c153..ee2bf16 100644 --- a/test/String.cpp +++ b/test/String.cpp @@ -398,3 +398,27 @@ TEST_CASE("SStrToInt", "[string]") { REQUIRE(result == 123); } } + +TEST_CASE("SStrUpper", "[string]") { + SECTION("rewrites lowercase string to uppercase correctly") { + auto lower = "foobar"; + auto upper = static_cast(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(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); + } +}