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())
|
if (pos >= str.size())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((str[pos] & 0x80) == 0)
|
const char c = str[pos];
|
||||||
return 1;
|
if(c >= 0xF0)
|
||||||
else if ((str[pos] & 0xC0) == 0xC0)
|
return 4;
|
||||||
return 2;
|
if(c >= 0xE0)
|
||||||
else
|
|
||||||
return 3;
|
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)
|
std::size_t StrUtils::Utf8StringLength(const std::string &str)
|
||||||
|
|
Loading…
Reference in New Issue