GetCodepointNext: Add 10xxxxxx checks to multibyte encodings.
This commit is contained in:
parent
41e9eda790
commit
101d30556e
|
|
@ -1894,18 +1894,21 @@ int GetCodepointNext(const char *text, int *codepointSize)
|
||||||
if (0xf0 == (0xf8 & ptr[0]))
|
if (0xf0 == (0xf8 & ptr[0]))
|
||||||
{
|
{
|
||||||
// 4 byte UTF-8 codepoint
|
// 4 byte UTF-8 codepoint
|
||||||
|
if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
|
||||||
codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]);
|
codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]);
|
||||||
*codepointSize = 4;
|
*codepointSize = 4;
|
||||||
}
|
}
|
||||||
else if (0xe0 == (0xf0 & ptr[0]))
|
else if (0xe0 == (0xf0 & ptr[0]))
|
||||||
{
|
{
|
||||||
// 3 byte UTF-8 codepoint */
|
// 3 byte UTF-8 codepoint */
|
||||||
|
if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
|
||||||
codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]);
|
codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]);
|
||||||
*codepointSize = 3;
|
*codepointSize = 3;
|
||||||
}
|
}
|
||||||
else if (0xc0 == (0xe0 & ptr[0]))
|
else if (0xc0 == (0xe0 & ptr[0]))
|
||||||
{
|
{
|
||||||
// 2 byte UTF-8 codepoint
|
// 2 byte UTF-8 codepoint
|
||||||
|
if((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } //10xxxxxx checks
|
||||||
codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]);
|
codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]);
|
||||||
*codepointSize = 2;
|
*codepointSize = 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user