diff --git a/src/ccmain/paragraphs.cpp b/src/ccmain/paragraphs.cpp index cb2413baa7..5265980d5d 100644 --- a/src/ccmain/paragraphs.cpp +++ b/src/ccmain/paragraphs.cpp @@ -2455,7 +2455,7 @@ static void InitializeRowInfo(bool after_recognition, int trailing_ws_idx = strlen(text.get()); // strip trailing space while (trailing_ws_idx > 0 && // isspace() only takes ASCII - ((text[trailing_ws_idx - 1] & 0x80) == 0) && + isascii(text[trailing_ws_idx - 1]) && isspace(text[trailing_ws_idx - 1])) trailing_ws_idx--; if (trailing_ws_idx > 0) { diff --git a/src/ccutil/scanutils.cpp b/src/ccutil/scanutils.cpp index f74094b0bf..8d7eb4c8e9 100644 --- a/src/ccutil/scanutils.cpp +++ b/src/ccutil/scanutils.cpp @@ -75,7 +75,7 @@ inline size_t LongBit() { static inline int SkipSpace(FILE *s) { int p; - while (isspace(p = fgetc(s))); + while (isascii(p = fgetc(s)) && isspace(p)); ungetc(p, s); // Make sure next char is available for reading return p; } @@ -108,9 +108,7 @@ static uintmax_t streamtoumax(FILE* s, int base) { uintmax_t v = 0; int d, c = 0; - for (c = fgetc(s); - isspace(static_cast(c)) && (c != EOF); - c = fgetc(s)) {} + for (c = fgetc(s); isascii(c) && isspace(c); c = fgetc(s)); // Single optional + or - if (c == '-' || c == '+') { @@ -151,9 +149,7 @@ static double streamtofloat(FILE* s) { int k = 1; int w = 0; - for (c = fgetc(s); - isspace(static_cast(c)) && (c != EOF); - c = fgetc(s)); + for (c = fgetc(s); isascii(c) && isspace(c); c = fgetc(s)); // Single optional + or - if (c == '-' || c == '+') { @@ -265,7 +261,7 @@ static int tvfscanf(FILE* stream, const char *format, va_list ap) { if (ch == '%') { state = ST_FLAGS; flags = 0; rank = RANK_INT; width = UINT_MAX; - } else if (isspace(static_cast(ch))) { + } else if (isascii(ch) && isspace(ch)) { SkipSpace(stream); } else { if (fgetc(stream) != ch) @@ -445,7 +441,7 @@ static int tvfscanf(FILE* stream, const char *format, va_list ap) { unsigned length = 0; while (width--) { q = fgetc(stream); - if (isspace(static_cast(q)) || q <= 0) { + if (isascii(q) && isspace(q) || q <= 0) { ungetc(q, stream); break; } diff --git a/src/wordrec/params_model.cpp b/src/wordrec/params_model.cpp index 1224a446a7..8512eda43a 100644 --- a/src/wordrec/params_model.cpp +++ b/src/wordrec/params_model.cpp @@ -58,7 +58,10 @@ bool ParamsModel::ParseLine(char *line, char** key, float *val) { if (line[0] == '#') return false; int end_of_key = 0; - while (line[end_of_key] && !isspace(line[end_of_key])) end_of_key++; + while (line[end_of_key] && + !(isascii(line[end_of_key]) && isspace(line[end_of_key]))) { + end_of_key++; + } if (!line[end_of_key]) { tprintf("ParamsModel::Incomplete line %s\n", line); return false;