1
4

2 回答 2

0

假设您正在使用的这个实现String::AsciiValue,似乎有一个length()方法

于 2013-07-17T09:31:25.883 回答
0

解决了。

UTF8 代码点:https ://en.wikipedia.org/wiki/UTF-8

基本思想是屏蔽字节并检查必须忽略多少字节才能完全读取多字节字符。

unsigned char masks[5] = { 192, 224, 240, 248, 252 };

Local<String> str = ...
String::Utf8Value s (str->ToString ());
unsigned char c;
int utf8Bytes = 0;

for (int i=0; (c = (*s)[i]) != 0; i++){
    //Ignore utf8 check for one byte chars
    if (c > 127){
        if (utf8Bytes){
            utf8Bytes--;
            continue;
        }

        //Check whether is a utf8 multibyte char
        for (int i=4; i>=0; i--){
            if ((c & r->masks[i]) == r->masks[i]){
                utf8Bytes = i + 1;
                break;
            }
        }

        if (utf8Bytes){
             //Do something if it's a multibyte char
        }

        continue;
    }

        //Do something to check lines, chars, etc
}
于 2013-07-17T11:00:42.327 回答