diff --git a/src/common/stringutils.cpp b/src/common/stringutils.cpp index b8639df3..fd8387f5 100644 --- a/src/common/stringutils.cpp +++ b/src/common/stringutils.cpp @@ -173,14 +173,19 @@ int StrUtils::Utf8CharSizeAt(const std::string &str, unsigned int pos) if (pos >= str.size()) return 0; - if ((str[pos] & 0x80) == 0) - return 1; - else if ((str[pos] & 0xC0) == 0xC0) - return 2; - else + const char c = str[pos]; + if(c >= 0xF0) + return 4; + if(c >= 0xE0) return 3; + if(c >= 0xC0) + return 2; - return 0; + // Invalid char - unexpected continuation byte + if(c >= 0x80) + return 0; + + return 1; } std::size_t StrUtils::Utf8StringLength(const std::string &str)