blob: 15dd51e8818c9507cbf80b85ffdb4b1fc3b4ca1d (
plain) (
blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/* See LICENSE file for copyright and license details. */
#include "lib-common.h"
enum libcharconv_result
libcharconv_enclosed_positive(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp)
{
uint_least32_t c;
size_t old_slen;
*n = 0;
for (; slen--; s++) {
old_slen = slen;
if (s[0] == '(') {
if (!slen--)
goto indeterminate;
if ((unsigned char)s[1] == 0xF0u) {
if (!slen--)
goto indeterminate;
if ((unsigned char)s[2] != 0x9Du)
goto no_match;
if (!slen--)
goto indeterminate;
if ((unsigned char)s[3] != 0x9Fu)
goto no_match;
if (!slen--)
goto indeterminate;
if (0xA2u > (unsigned char)s[4] || (unsigned char)s[4] > 0xABu)
goto no_match;
if (!slen--)
goto indeterminate;
if (s[5] != ')')
goto no_match;
c = (unsigned char)s[4] - 0xA2u;
if (c == 0)
c = UINT32_C(0x1F10B);
else
c += UINT32_C(0x2780) - 1u;
goto conv6;
} else if (s[1] == '(') {
if (!slen--)
goto indeterminate;
if (s[2] == '1') {
if (!slen--)
goto indeterminate;
if (s[3] == ')') {
if (!slen--)
goto indeterminate;
if (s[4] != ')')
goto no_match;
c = UINT32_C(0x24F5);
goto conv5;
} else if (s[3] == '0') {
if (!slen--)
goto indeterminate;
if (s[4] != ')')
goto no_match;
if (!slen--)
goto indeterminate;
if (s[5] != ')')
goto no_match;
c = UINT32_C(0x24FE);
goto conv6;
} else {
goto no_match;
}
} else if ('2' <= s[2] && s[2] <= '9') {
c = UINT32_C(0x24F6) + (unsigned)(s[2] - '2');
if (!slen--)
goto indeterminate;
if (s[3] != ')')
goto no_match;
if (!slen--)
goto indeterminate;
if (s[4] != ')')
goto no_match;
goto conv5;
}
} else if (s[1] == '1') {
if (!slen--)
goto indeterminate;
if (s[2] == ')') {
c = UINT32_C(0x2460);
goto conv3;
} else if ('0' <= s[2] && s[2] <= '9') {
if (!slen--)
goto indeterminate;
if (s[3] != ')')
goto no_match;
c = UINT32_C(0x2469) + (unsigned)(s[2] - '0');
goto conv4;
} else {
goto no_match;
}
} else if (s[1] == '2') {
if (!slen--)
goto indeterminate;
if (s[2] == ')') {
c = UINT32_C(0x2461);
goto conv3;
} else if (s[2] == '0') {
if (!slen--)
goto indeterminate;
if (s[3] != ')')
goto no_match;
c = UINT32_C(0x2473);
goto conv4;
} else {
goto no_match;
}
} else if (s[1] == '0') {
if (!slen--)
goto indeterminate;
if (s[2] != ')')
goto no_match;
c = UINT32_C(0x24EA);
goto conv3;
} else if ('3' <= s[1] && s[1] <= '9') {
if (!slen--)
goto indeterminate;
if (s[2] != ')')
goto no_match;
c = UINT32_C(0x2460) + (unsigned)(s[1] - '1');
goto conv3;
} else if ('a' <= s[1] && s[1] <= 'z') {
if (!slen--)
goto indeterminate;
if (s[2] != ')')
goto no_match;
c = UINT32_C(0x24D0) + (unsigned)(s[1] - 'a');
goto conv3;
} else if ('A' <= s[1] && s[1] <= 'Z') {
if (!slen--)
goto indeterminate;
if (s[2] != ')')
goto no_match;
c = UINT32_C(0x24B6) + (unsigned)(s[1] - 'A');
goto conv3;
} else {
goto no_match;
}
} else if (s[0] == '[') {
if (!slen--)
goto indeterminate;
if (s[1] == 'd') {
if (!slen--)
goto indeterminate;
if (s[2] != ']')
goto no_match;
c = UINT32_C(0x1F1A5);
goto conv3;
} else if ('A' <= s[1] && s[1] <= 'Z') {
if (!slen--)
goto indeterminate;
if (s[2] != ']')
goto no_match;
c = UINT32_C(0x1F130) + (unsigned)(s[1] - 'A');
goto conv3;
}
} else {
no_match:
slen = old_slen;
*n += 1u;
break;
}
}
no_conv:
return LIBCHARCONV_NO_CONVERT;
indeterminate:
if (*n)
goto no_conv;
return LIBCHARCONV_INDETERMINATE;
conv3:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 3u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
conv4:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 4u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
conv5:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 5u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
conv6:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 6u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
}
|