#include <stdarg.h>
#include <string.h>
#include "third_party/utf/utf.h"
#include "third_party/utf/utfdef.h"
Go to the source code of this file.
|
enum | {
Bit1 = 7
, Bitx = 6
, Bit2 = 5
, Bit3 = 4
,
Bit4 = 3
, Bit5 = 2
, T1 = ((1 << (Bit1 + 1)) - 1) ^ 0xFF
, Tx = ((1 << (Bitx + 1)) - 1) ^ 0xFF
,
T2 = ((1 << (Bit2 + 1)) - 1) ^ 0xFF
, T3 = ((1 << (Bit3 + 1)) - 1) ^ 0xFF
, T4 = ((1 << (Bit4 + 1)) - 1) ^ 0xFF
, T5 = ((1 << (Bit5 + 1)) - 1) ^ 0xFF
,
Rune1 = (1 << (Bit1 + 0 * Bitx)) - 1
, Rune2 = (1 << (Bit2 + 1 * Bitx)) - 1
, Rune3 = (1 << (Bit3 + 2 * Bitx)) - 1
, Rune4 = (1 << (Bit4 + 3 * Bitx)) - 1
,
Maskx = (1 << Bitx) - 1
, Testx = Maskx ^ 0xFF
, Bad = Runeerror
} |
|
◆ anonymous enum
Enumerator |
---|
Bit1 | |
Bitx | |
Bit2 | |
Bit3 | |
Bit4 | |
Bit5 | |
T1 | |
Tx | |
T2 | |
T3 | |
T4 | |
T5 | |
Rune1 | |
Rune2 | |
Rune3 | |
Rune4 | |
Maskx | |
Testx | |
Bad | |
Definition at line 19 of file rune.c.
19 {
26
27 T1 = ((1 << (
Bit1 + 1)) - 1) ^ 0xFF,
28 Tx = ((1 << (
Bitx + 1)) - 1) ^ 0xFF,
29 T2 = ((1 << (
Bit2 + 1)) - 1) ^ 0xFF,
30 T3 = ((1 << (
Bit3 + 1)) - 1) ^ 0xFF,
31 T4 = ((1 << (
Bit4 + 1)) - 1) ^ 0xFF,
32 T5 = ((1 << (
Bit5 + 1)) - 1) ^ 0xFF,
33
38
39
42
44};
◆ charntorune()
int charntorune |
( |
Rune * |
rune, |
|
|
const char * |
str, |
|
|
int |
length |
|
) |
| |
Definition at line 64 of file rune.c.
64 {
65 int c, c1, c2, c3;
66 long l;
67
68
69 if (length <= 0) {
70 goto badlen;
71 }
72
73
74
75
76
79 *rune = c;
80 return 1;
81 }
82
83
84 if (length <= 1) {
85 goto badlen;
86 }
87
88
89
90
91
94 goto bad;
97 goto bad;
100 goto bad;
101 *rune = l;
102 return 2;
103 }
104
105
106 if (length <= 2) {
107 goto badlen;
108 }
109
110
111
112
113
116 goto bad;
120 goto bad;
121 *rune = l;
122 return 3;
123 }
124
125 if (length <= 3)
126 goto badlen;
127
128
129
130
131
134 goto bad;
138 goto bad;
140 goto bad;
141 *rune = l;
142 return 4;
143 }
144
145
146
147
148
149
150
151bad:
153 return 1;
154badlen:
156 return 0;
157}
◆ chartorune()
int chartorune |
( |
Rune * |
rune, |
|
|
const char * |
str |
|
) |
| |
Definition at line 163 of file rune.c.
163 {
164 int c, c1, c2, c3;
165 long l;
166
167
168
169
170
173 *rune = c;
174 return 1;
175 }
176
177
178
179
180
183 goto bad;
186 goto bad;
189 goto bad;
190 *rune = l;
191 return 2;
192 }
193
194
195
196
197
200 goto bad;
204 goto bad;
205 *rune = l;
206 return 3;
207 }
208
209
210
211
212
215 goto bad;
219 goto bad;
221 goto bad;
222 *rune = l;
223 return 4;
224 }
225
226
227
228
229
230
231
232
233
234bad:
236 return 1;
237}
◆ fullrune()
int fullrune |
( |
const char * |
str, |
|
|
int |
n |
|
) |
| |
Definition at line 326 of file rune.c.
326 {
327 if (n > 0) {
328 int c = *(
uchar *)str;
330 return 1;
331 if (n > 1) {
333 return 1;
334 if (n > 2) {
335 if (c < T4 || n > 3)
336 return 1;
337 }
338 }
339 }
340 return 0;
341}
◆ isvalidcharntorune()
int isvalidcharntorune |
( |
const char * |
str, |
|
|
int |
length, |
|
|
Rune * |
rune, |
|
|
int * |
consumed |
|
) |
| |
Definition at line 239 of file rune.c.
239 {
241 return *rune !=
Runeerror || *consumed == 3;
242}
int charntorune(Rune *rune, const char *str, int length)
◆ runelen()
Definition at line 299 of file rune.c.
299 {
300 char str[10];
301
303}
int runetochar(char *str, const Rune *rune)
◆ runenlen()
int runenlen |
( |
const Rune * |
r, |
|
|
int |
nrune |
|
) |
| |
Definition at line 305 of file rune.c.
305 {
306 int nb;
308
309 nb = 0;
310 while (nrune--) {
311 c = *r++;
313 nb++;
315 nb += 2;
317 nb += 3;
319 nb += 4;
320 else
321 nb += 3;
322 }
323 return nb;
324}
◆ runetochar()
int runetochar |
( |
char * |
str, |
|
|
const Rune * |
rune |
|
) |
| |
Definition at line 244 of file rune.c.
244 {
245
246 unsigned long c;
247
248
249
250
251
252 c = *rune;
254 str[0] = c;
255 return 1;
256 }
257
258
259
260
261
263 str[0] =
T2 | (c >> 1 *
Bitx);
265 return 2;
266 }
267
268
269
270
271
272
273
276
277
278
279
280
282 str[0] =
T3 | (c >> 2 *
Bitx);
285 return 3;
286 }
287
288
289
290
291
292 str[0] =
T4 | (c >> 3 *
Bitx);
296 return 4;
297}