- 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.
This commit is contained in:
Christoph Oelckers 2019-03-14 21:42:02 +01:00
parent 087353f00b
commit 50ebca20bb
2 changed files with 11 additions and 6 deletions

View file

@ -75,6 +75,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)) )
@ -104,7 +107,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)
{ {
@ -137,12 +140,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;
} }
@ -160,7 +163,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);

View file

@ -150,13 +150,15 @@ bool FStringTable::readSheetIntoTable(xlsxioreader reader, const char *sheetname
int column = 0; int column = 0;
char *value; char *value;
table.Reserve(1); table.Reserve(1);
auto myisspace = [](int ch) { return ch == '\t' || ch == '\r' || ch == '\n' || ch == ' '; };
while ((value = xlsxioread_sheet_next_cell(sheet)) != nullptr) while ((value = xlsxioread_sheet_next_cell(sheet)) != nullptr)
{ {
auto vcopy = value; auto vcopy = value;
if (table.Size() <= (unsigned)row) table.Reserve(1); if (table.Size() <= (unsigned)row) table.Reserve(1);
while (*vcopy && iswspace((unsigned char)*vcopy)) vcopy++; // skip over leaading whitespace; while (*vcopy && myisspace((unsigned char)*vcopy)) vcopy++; // skip over leaading whitespace;
auto vend = vcopy + strlen(vcopy); auto vend = vcopy + strlen(vcopy);
while (vend > vcopy && iswspace((unsigned char)vend[-1])) *--vend = 0; // skip over trailing whitespace while (vend > vcopy && myisspace((unsigned char)vend[-1])) *--vend = 0; // skip over trailing whitespace
ProcessEscapes(vcopy); ProcessEscapes(vcopy);
table[row].Push(vcopy); table[row].Push(vcopy);
column++; column++;