44 | | // Note, this does not recognize invalid chars |
45 | | uint32 c = firstChar; |
46 | | if (c < 0x80) |
47 | | return 1; |
48 | | if (c < 0xe0) |
49 | | return 2; |
50 | | return c < 0xf0 ? 3 : 4; |
| 38 | const unsigned char BIT3 = 8; |
| 39 | const unsigned char BIT4 = 16; |
| 40 | const unsigned char BIT5 = 32; |
| 41 | const unsigned char BIT6 = 64; |
| 42 | const unsigned char BIT7 = 128; |
| 43 | |
| 44 | uchar c = (uchar)firstChar; |
| 45 | uchar invc = ~c; |
| 46 | |
| 47 | if ((invc & BIT7) == BIT7) |
| 48 | return 1; else |
| 49 | if (((c & (BIT7 | BIT6)) == (BIT7 | BIT6)) |
| 50 | && ((invc & BIT5) == BIT5)) |
| 51 | return 2; else |
| 52 | if (((c & (BIT7 | BIT6 | BIT5)) == (BIT7 | BIT6 | BIT5)) |
| 53 | && ((invc & BIT4) == BIT4)) |
| 54 | return 3; else |
| 55 | if (((c & (BIT7 | BIT6 | BIT5 | BIT4)) == (BIT7 | BIT6 | BIT5 | BIT4)) |
| 56 | && ((invc & BIT3) == BIT3)) |
| 57 | return 4; else |
| 58 | return 0; /* Error, no UTF8 Byte */ |