Detect invalid values in StringUtils::Utf8CharSizeAt()
parent
ebcb124b0e
commit
86ef158c00
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue