- do not use iswspace to check raw UTF-8.

At least under MSVC this function reports 0x85 as whitespace, but it is a continuation byte for UTF-8 sequences and may not be treated as whitespace.
(patch by Graf)
This commit is contained in:
drfrag 2019-04-10 17:53:57 +02:00
parent 8a9ffb3031
commit a31c9273dd

View file

@ -290,6 +290,9 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
bool lastWasSpace = false; bool lastWasSpace = false;
int kerning = font->GetDefaultKerning (); int kerning = font->GetDefaultKerning ();
// The real isspace is a bit too badly defined, so use our own one
auto myisspace = [](int ch) { return ch == '\t' || ch == '\r' || ch == '\n' || ch == ' '; };
w = 0; w = 0;
while ( (c = GetCharFromString(string)) ) while ( (c = GetCharFromString(string)) )
@ -319,7 +322,7 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
continue; continue;
} }
if (iswspace(c)) if (myisspace(c))
{ {
if (!lastWasSpace) if (!lastWasSpace)
{ {
@ -352,12 +355,12 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
start = space; start = space;
space = NULL; space = NULL;
while (*start && iswspace (*start) && *start != '\n') while (*start && myisspace (*start) && *start != '\n')
start++; start++;
if (*start == '\n') if (*start == '\n')
start++; start++;
else else
while (*start && iswspace (*start)) while (*start && myisspace (*start))
start++; start++;
string = start; string = start;
} }
@ -375,7 +378,7 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
while (s < string) while (s < string)
{ {
// If there is any non-white space in the remainder of the string, add it. // If there is any non-white space in the remainder of the string, add it.
if (!iswspace (*s++)) if (!myisspace (*s++))
{ {
auto i = Lines.Reserve(1); auto i = Lines.Reserve(1);
breakit (&Lines[i], font, start, string, linecolor); breakit (&Lines[i], font, start, string, linecolor);