blob: 881ca089352dc190e98a1046c897dff41145777c (
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
|
/* 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++) {
PLAIN_CASE_SINGLE('k', 0x1743);
PLAIN_CASE_SINGLE('g', 0x1744);
PLAIN_CASE_SELECT("tdnpbmyrlwsh", 0x1746);
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;
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;
}
|