Commit 0b49b59c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

IsUTF8: use clz

parent 15b6bc54
...@@ -286,25 +286,20 @@ static char *CheckUTF8( char *str, char rep ) ...@@ -286,25 +286,20 @@ static char *CheckUTF8( char *str, char rep )
for (;;) for (;;)
{ {
uint8_t c = ptr[0]; uint8_t c = ptr[0];
int charlen = -1;
if (c == '\0') if (c == '\0')
break; break;
for (int i = 0; i < 7; i++) if (c > 0xF4)
if ((c >> (7 - i)) == ((0xff >> (7 - i)) ^ 1)) goto error;
{
charlen = i;
break;
}
int charlen = clz8 (c ^ 0xFF);
switch (charlen) switch (charlen)
{ {
case 0: // 7-bit ASCII character -> OK case 0: // 7-bit ASCII character -> OK
ptr++; ptr++;
continue; continue;
case -1: // 1111111x -> error
case 1: // continuation byte -> error case 1: // continuation byte -> error
goto error; goto error;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment