Differences between revisions 2 and 3
Revision 2 as of 2009-11-28 14:54:13
Size: 1244
Editor: Elias
Comment: 删除对PageComment2组件的引用
Revision 3 as of 2009-12-25 07:09:26
Size: 1244
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
[[TableOfContents]] <<TableOfContents>>
Line 6: Line 6:
[[Include(ZPyUGnav)]] <<Include(ZPyUGnav)>>
Line 53: Line 53:
创建 by -- ZoomQuiet [[[DateTime(2008-06-05T01:20:23Z)]]] 创建 by -- ZoomQuiet [<<DateTime(2008-06-05T01:20:23Z)>>]

UTF-8字符串长度的程序

张沈鹏 <[email protected]>
reply-to        [email protected]
to      [email protected]
date    Thu, Jun 5, 2008 at 9:12 AM
subject [CPyUG:53685] 谁能解释一下我在这个网页看到的UTF-8字符串长度的程序?

谁能解释一下我在这个网页看到的UTF-8字符串长度的程序?

http://wangcong.org/blog/?p=357

在这里看到这么一个计算UTF-8字符串长度的程序:

  1.     int my_strlen_utf8_c(char *s) {
  2.       int i = 0, j = 0;
  3.       while (s[i]) {
  4.         if ((s[i] & 0xc0) != 0x80) j++;
  5.         i++;
  6.       }
  7.       return j;
  8.     }

不解。查wikipedia,得一表:

00000000 00000000 0zzzzzzz 0zzzzzzz
00000000 00000yyy yyzzzzzz 110yyyyy 10zzzzzz
00000000 xxxxyyyy yyzzzzzz 1110xxxx 10yyyyyy 10zzzzzz
000wwwxx xxxxyyyy yyzzzzzz 11110www 10xxxxxx 10yyyyyy 10zzzzzz

顿悟。 """


反馈

创建 by -- ZoomQuiet [2008-06-05 01:20:23]

MiscItems/2008-06-05 (last edited 2009-12-25 07:09:26 by localhost)