From 7449111a00c7e62a898f54d3c59dcefe6b307ead Mon Sep 17 00:00:00 2001 From: MrSimbax Date: Mon, 6 Jul 2020 13:49:57 +0200 Subject: [PATCH] Fix linter errors "comparison of constant 240 with expression of type 'const char' is always false" also a whitespace issue Changed the inequalities to bitwise comparisons, which hopefully don't care about the sign. I was considering just casting `c` to `unsigned char` but I doubt it would be safe and multiplatform. --- src/common/stringutils.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/stringutils.cpp b/src/common/stringutils.cpp index 5896a332..5e7afd1e 100644 --- a/src/common/stringutils.cpp +++ b/src/common/stringutils.cpp @@ -175,17 +175,17 @@ int StrUtils::Utf8CharSizeAt(const std::string &str, unsigned int pos) return 0; const char c = str[pos]; - if(c >= 0xF0) + if((c & 0b11111000) == 0b11110000) return 4; - if(c >= 0xE0) + if((c & 0b11110000) == 0b11100000) return 3; - if(c >= 0xC0) + if((c & 0b11100000) == 0b11000000) return 2; // Invalid char - unexpected continuation byte - if(c >= 0x80) + if((c & 0b11000000) == 0b10000000) throw new std::invalid_argument("Unexpected UTF-8 continuation byte"); - + return 1; }