blob: 8abad6ae424509eb7e5435835a6d52b2d0132b31 (
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
|
/* See LICENSE file for copyright and license details. */
#include "lib-common.h"
enum libcharconv_result
libcharconv_buhid(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp)
{
uint_least32_t c;
*n = 0;
for (; slen--; s++) {
switch (s[0]) {
case 'A': case 'a': c = UINT32_C(0x1740); goto conv1;
case 'I': case 'i': c = UINT32_C(0x1741); goto conv1;
case 'U': case 'u': c = UINT32_C(0x1742); goto conv1;
case '^':
if (!slen)
return LIBCHARCONV_INDETERMINATE;
switch (s[1]) {
case 'I': case 'i': c = UINT32_C(0x1752); goto conv2;
case 'U': case 'u': c = UINT32_C(0x1753); goto conv2;
default:
goto no_match;
}
goto no_match;
case 'B': case 'b': c = UINT32_C(0x174A); goto conv;
case 'D': case 'd': c = UINT32_C(0x1747); goto conv;
case 'G': case 'g': c = UINT32_C(0x1744); goto conv;
case 'H': case 'h': c = UINT32_C(0x1751); goto conv;
case 'K': case 'k': c = UINT32_C(0x1743); goto conv;
case 'L': case 'l': c = UINT32_C(0x174E); goto conv;
case 'M': case 'm': c = UINT32_C(0x174B); goto conv;
case 'N': case 'n': c = UINT32_C(0x1748); goto conv;
case 'P': case 'p': c = UINT32_C(0x1749); goto conv;
case 'R': case 'r': c = UINT32_C(0x174D); goto conv;
case 'S': case 's': c = UINT32_C(0x1750); goto conv;
case 'T': case 't': c = UINT32_C(0x1746); goto conv;
case 'Y': case 'y': c = UINT32_C(0x174C); goto conv;
case 'W': case 'w': c = UINT32_C(0x174F); goto conv;
default:
no_match:
*n += 1u;
break;
}
}
no_conv:
return LIBCHARCONV_NO_CONVERT;
conv:
if (*n)
goto no_conv;
conv_again:
if (!slen)
return LIBCHARCONV_INDETERMINATE;
switch (s[1]) {
case 'A': case 'a':
if (*ncp >= 1u)
cp[0] = c;
*n += 2u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
case 'I': case 'i':
if (*ncp >= 1u)
cp[0] = c;
if (*ncp >= 2u)
cp[1] = UINT32_C(0x1752);
*n += 2u;
*ncp = 2u;
return LIBCHARCONV_CONVERTED;
case 'U': case 'u':
if (*ncp >= 1u)
cp[0] = c;
if (*ncp >= 2u)
cp[1] = UINT32_C(0x1753);
*n += 2u;
*ncp = 2u;
return LIBCHARCONV_CONVERTED;
case 'G': case 'g':
if (c == UINT32_C(0x1745))
goto no_match;
if (s[0] != 'N' && s[0] != 'n')
goto no_match;
c = UINT32_C(0x1745);
*n += 1u;
slen--;
s++;
goto conv_again;
default:
goto no_match;
}
conv1:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 1u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
conv2:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 2u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
}
|