diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index 8b45f6e928..636409629c 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -447,6 +447,12 @@ namespace String return utf8_write_codepoint(dst, codepoint); } + bool IsWhiteSpace(codepoint_t codepoint) + { + // 0x3000 is the 'ideographic space', a 'fullwidth' character used in CJK languages. + return iswspace((wchar_t)codepoint) || codepoint == 0x3000; + } + utf8 * Trim(utf8 * str) { utf8 * firstNonWhitespace = nullptr; @@ -456,7 +462,7 @@ namespace String utf8 * nextCh; while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0') { - if (codepoint <= WCHAR_MAX && !iswspace((wchar_t)codepoint)) + if (codepoint <= WCHAR_MAX && !IsWhiteSpace(codepoint)) { if (firstNonWhitespace == nullptr) { @@ -496,7 +502,7 @@ namespace String const utf8 * nextCh; while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0') { - if (codepoint <= WCHAR_MAX && !iswspace((wchar_t)codepoint)) + if (codepoint <= WCHAR_MAX && !IsWhiteSpace(codepoint)) { return ch; } @@ -519,7 +525,7 @@ namespace String const utf8 * endSubstr = nullptr; while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0') { - bool isWhiteSpace = codepoint <= WCHAR_MAX && iswspace((wchar_t)codepoint); + bool isWhiteSpace = codepoint <= WCHAR_MAX && IsWhiteSpace(codepoint); if (!isWhiteSpace) { if (startSubstr == nullptr) diff --git a/src/openrct2/core/String.hpp b/src/openrct2/core/String.hpp index 895e419ce6..48e96066cb 100644 --- a/src/openrct2/core/String.hpp +++ b/src/openrct2/core/String.hpp @@ -94,6 +94,7 @@ namespace String codepoint_t GetNextCodepoint(const utf8 * ptr, const utf8 * * nextPtr = nullptr); utf8 * WriteCodepoint(utf8 * dst, codepoint_t codepoint); + bool IsWhiteSpace(codepoint_t codepoint); utf8 * Trim(utf8 * str); const utf8 * TrimStart(const utf8 * str); utf8 * TrimStart(utf8 * buffer, size_t bufferSize, const utf8 * src); diff --git a/test/tests/StringTest.cpp b/test/tests/StringTest.cpp index 5b481c5535..fc8a147340 100644 --- a/test/tests/StringTest.cpp +++ b/test/tests/StringTest.cpp @@ -18,6 +18,8 @@ INSTANTIATE_TEST_CASE_P(TrimData, StringTest, testing::Values( TCase(" ", ""), TCase(" ストリング", "ストリング"), TCase("ストリング ", "ストリング"), + TCase(" ストリング ", "ストリング"), + TCase("    ", ""), TCase("", ""), TCase("\n", ""), TCase("\n\n\n\r\n", ""),