This source file includes following definitions.
- u8_strmbtouc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include <config.h>
28
29
30 #include "unistr.h"
31
32 int
33 u8_strmbtouc (ucs4_t *puc, const uint8_t *s)
34 {
35
36 uint8_t c = *s;
37
38 if (c < 0x80)
39 {
40 *puc = c;
41 return (c != 0 ? 1 : 0);
42 }
43 if (c >= 0xc2)
44 {
45 if (c < 0xe0)
46 {
47 if ((s[1] ^ 0x80) < 0x40)
48 {
49 *puc = ((unsigned int) (c & 0x1f) << 6)
50 | (unsigned int) (s[1] ^ 0x80);
51 return 2;
52 }
53 }
54 else if (c < 0xf0)
55 {
56 if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
57 && (c >= 0xe1 || s[1] >= 0xa0)
58 && (c != 0xed || s[1] < 0xa0))
59 {
60 *puc = ((unsigned int) (c & 0x0f) << 12)
61 | ((unsigned int) (s[1] ^ 0x80) << 6)
62 | (unsigned int) (s[2] ^ 0x80);
63 return 3;
64 }
65 }
66 else if (c < 0xf8)
67 {
68 if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
69 && (s[3] ^ 0x80) < 0x40
70 && (c >= 0xf1 || s[1] >= 0x90)
71 && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)))
72 {
73 *puc = ((unsigned int) (c & 0x07) << 18)
74 | ((unsigned int) (s[1] ^ 0x80) << 12)
75 | ((unsigned int) (s[2] ^ 0x80) << 6)
76 | (unsigned int) (s[3] ^ 0x80);
77 return 4;
78 }
79 }
80 }
81
82 return -1;
83 }