10utf8_mbtowc (conv_t conv, ucs4_t *pwc,
const unsigned char *s,
int n)
12 unsigned char c = s[0];
17 }
else if (c < 0xc2) {
19 }
else if (c < 0xe0) {
22 if (!((s[1] ^ 0x80) < 0x40))
24 *pwc = ((ucs4_t) (c & 0x1f) << 6)
25 | (ucs4_t) (s[1] ^ 0x80);
27 }
else if (c < 0xf0) {
30 if (!((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
31 && (c >= 0xe1 || s[1] >= 0xa0)))
33 *pwc = ((ucs4_t) (c & 0x0f) << 12)
34 | ((ucs4_t) (s[1] ^ 0x80) << 6)
35 | (ucs4_t) (s[2] ^ 0x80);
37 }
else if (c < 0xf8) {
40 if (!((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
41 && (s[3] ^ 0x80) < 0x40
42 && (c >= 0xf1 || s[1] >= 0x90)))
44 *pwc = ((ucs4_t) (c & 0x07) << 18)
45 | ((ucs4_t) (s[1] ^ 0x80) << 12)
46 | ((ucs4_t) (s[2] ^ 0x80) << 6)
47 | (ucs4_t) (s[3] ^ 0x80);
49 }
else if (c < 0xfc) {
52 if (!((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
53 && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40
54 && (c >= 0xf9 || s[1] >= 0x88)))
56 *pwc = ((ucs4_t) (c & 0x03) << 24)
57 | ((ucs4_t) (s[1] ^ 0x80) << 18)
58 | ((ucs4_t) (s[2] ^ 0x80) << 12)
59 | ((ucs4_t) (s[3] ^ 0x80) << 6)
60 | (ucs4_t) (s[4] ^ 0x80);
62 }
else if (c < 0xfe) {
65 if (!((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
66 && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40
67 && (s[5] ^ 0x80) < 0x40
68 && (c >= 0xfd || s[1] >= 0x84)))
70 *pwc = ((ucs4_t) (c & 0x01) << 30)
71 | ((ucs4_t) (s[1] ^ 0x80) << 24)
72 | ((ucs4_t) (s[2] ^ 0x80) << 18)
73 | ((ucs4_t) (s[3] ^ 0x80) << 12)
74 | ((ucs4_t) (s[4] ^ 0x80) << 6)
75 | (ucs4_t) (s[5] ^ 0x80);
82utf8_wctomb (conv_t conv,
unsigned char *r, ucs4_t wc,
int n)
89 else if (wc < 0x10000)
91 else if (wc < 0x200000)
93 else if (wc < 0x4000000)
95 else if (wc <= 0x7fffffff)
102 case 6: r[5] = 0x80 | (wc & 0x3f); wc = wc >> 6; wc |= 0x4000000;
103 case 5: r[4] = 0x80 | (wc & 0x3f); wc = wc >> 6; wc |= 0x200000;
104 case 4: r[3] = 0x80 | (wc & 0x3f); wc = wc >> 6; wc |= 0x10000;
105 case 3: r[2] = 0x80 | (wc & 0x3f); wc = wc >> 6; wc |= 0x800;
106 case 2: r[1] = 0x80 | (wc & 0x3f); wc = wc >> 6; wc |= 0xc0;