- 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;
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;
while ( (c = GetCharFromString(string)) )
@ -104,7 +107,7 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
continue;
}
if (iswspace(c))
if (myisspace(c))
{
if (!lastWasSpace)
{
@ -137,12 +140,12 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
start = space;
space = NULL;
while (*start && iswspace (*start) && *start != '\n')
while (*start && myisspace (*start) && *start != '\n')
start++;
if (*start == '\n')
start++;
else
while (*start && iswspace (*start))
while (*start && myisspace (*start))
start++;
string = start;
}
@ -160,7 +163,7 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
while (s < string)
{
// 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);
breakit (&Lines[i], font, start, string, linecolor);

View file

@ -150,13 +150,15 @@ bool FStringTable::readSheetIntoTable(xlsxioreader reader, const char *sheetname
int column = 0;
char *value;
table.Reserve(1);
auto myisspace = [](int ch) { return ch == '\t' || ch == '\r' || ch == '\n' || ch == ' '; };
while ((value = xlsxioread_sheet_next_cell(sheet)) != nullptr)
{
auto vcopy = value;
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);
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);
table[row].Push(vcopy);
column++;