16,549
社区成员




bool isutf8(CHAR *str)
{
int i = 0;
int size = strlen(str);
while(i < size)
{
int step = 0;
if((str[i] & 0x80) == 0x00)
{
step = 1;
}
else if((str[i] & 0xe0) == 0xc0)
{
if(i + 1 >= size) return false;
if((str[i + 1] & 0xc0) != 0x80) return false;
step = 2;
}
else if((str[i] & 0xf0) == 0xe0)
{
if(i + 2 >= size) return false;
if((str[i + 1] & 0xc0) != 0x80) return false;
if((str[i + 2] & 0xc0) != 0x80) return false;
step = 3;
}
else
{
return false;
}
i += step;
}
if(i == size) return true;
return false;
}