mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-20 14:23:08 +01:00
Trim ideographic spaces as well.
This commit is contained in:
committed by
Michael Steenbeek
parent
6c26009f19
commit
4bc2ad18c4
@@ -447,6 +447,12 @@ namespace String
|
|||||||
return utf8_write_codepoint(dst, codepoint);
|
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 * Trim(utf8 * str)
|
||||||
{
|
{
|
||||||
utf8 * firstNonWhitespace = nullptr;
|
utf8 * firstNonWhitespace = nullptr;
|
||||||
@@ -456,7 +462,7 @@ namespace String
|
|||||||
utf8 * nextCh;
|
utf8 * nextCh;
|
||||||
while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0')
|
while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0')
|
||||||
{
|
{
|
||||||
if (codepoint <= WCHAR_MAX && !iswspace((wchar_t)codepoint))
|
if (codepoint <= WCHAR_MAX && !IsWhiteSpace(codepoint))
|
||||||
{
|
{
|
||||||
if (firstNonWhitespace == nullptr)
|
if (firstNonWhitespace == nullptr)
|
||||||
{
|
{
|
||||||
@@ -496,7 +502,7 @@ namespace String
|
|||||||
const utf8 * nextCh;
|
const utf8 * nextCh;
|
||||||
while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0')
|
while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0')
|
||||||
{
|
{
|
||||||
if (codepoint <= WCHAR_MAX && !iswspace((wchar_t)codepoint))
|
if (codepoint <= WCHAR_MAX && !IsWhiteSpace(codepoint))
|
||||||
{
|
{
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
@@ -519,7 +525,7 @@ namespace String
|
|||||||
const utf8 * endSubstr = nullptr;
|
const utf8 * endSubstr = nullptr;
|
||||||
while ((codepoint = GetNextCodepoint(ch, &nextCh)) != '\0')
|
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 (!isWhiteSpace)
|
||||||
{
|
{
|
||||||
if (startSubstr == nullptr)
|
if (startSubstr == nullptr)
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ namespace String
|
|||||||
codepoint_t GetNextCodepoint(const utf8 * ptr, const utf8 * * nextPtr = nullptr);
|
codepoint_t GetNextCodepoint(const utf8 * ptr, const utf8 * * nextPtr = nullptr);
|
||||||
utf8 * WriteCodepoint(utf8 * dst, codepoint_t codepoint);
|
utf8 * WriteCodepoint(utf8 * dst, codepoint_t codepoint);
|
||||||
|
|
||||||
|
bool IsWhiteSpace(codepoint_t codepoint);
|
||||||
utf8 * Trim(utf8 * str);
|
utf8 * Trim(utf8 * str);
|
||||||
const utf8 * TrimStart(const utf8 * str);
|
const utf8 * TrimStart(const utf8 * str);
|
||||||
utf8 * TrimStart(utf8 * buffer, size_t bufferSize, const utf8 * src);
|
utf8 * TrimStart(utf8 * buffer, size_t bufferSize, const utf8 * src);
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ INSTANTIATE_TEST_CASE_P(TrimData, StringTest, testing::Values(
|
|||||||
TCase(" ", ""),
|
TCase(" ", ""),
|
||||||
TCase(" ストリング", "ストリング"),
|
TCase(" ストリング", "ストリング"),
|
||||||
TCase("ストリング ", "ストリング"),
|
TCase("ストリング ", "ストリング"),
|
||||||
|
TCase(" ストリング ", "ストリング"),
|
||||||
|
TCase(" ", ""),
|
||||||
TCase("", ""),
|
TCase("", ""),
|
||||||
TCase("\n", ""),
|
TCase("\n", ""),
|
||||||
TCase("\n\n\n\r\n", ""),
|
TCase("\n\n\n\r\n", ""),
|
||||||
|
|||||||
Reference in New Issue
Block a user