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
|
/* See LICENSE file for copyright and license details. */
#include "lib-common.h"
static struct {
uint_least32_t a;
uint_least32_t b;
} pairs[] = {
{UINT32_C(0x0032), UINT32_C(0x218A)},
{UINT32_C(0x0033), UINT32_C(0x218B)},
{UINT32_C(0x2616), UINT32_C(0x26C9)},
{UINT32_C(0x2617), UINT32_C(0x26CA)},
{UINT32_C(0x0021), UINT32_C(0x00A1)},
{UINT32_C(0x003F), UINT32_C(0x00BF)},
{UINT32_C(0x2E35), UINT32_C(0x003B)},
{UINT32_C(0x203D), UINT32_C(0x2E18)},
{UINT32_C(0xA4EF), (uint_least32_t)'A'},
{UINT32_C(0xA4ED), (uint_least32_t)'B'},
{UINT32_C(0xA4DB), (uint_least32_t)'C'},
{UINT32_C(0xA4F7), (uint_least32_t)'D'},
{UINT32_C(0xA4F1), (uint_least32_t)'E'},
{UINT32_C(0xA4DE), (uint_least32_t)'F'}, /* there is a letterlike alternative */
{UINT32_C(0x2132), (uint_least32_t)'F'}, /* secondary alternative */
{UINT32_C(0xA4E8), (uint_least32_t)'G'}, /* the one in letterlike is sans-serif */
{UINT32_C(0xA4E9), (uint_least32_t)'J'},
{UINT32_C(0xA4D8), (uint_least32_t)'K'},
{UINT32_C(0xA4F6), (uint_least32_t)'L'}, /* the one in letterlike is sans-serif */
{UINT32_C(0xA4D2), (uint_least32_t)'P'},
{UINT32_C(0xA4E4), (uint_least32_t)'R'},
{UINT32_C(0xA4D5), (uint_least32_t)'Y'}, /* the one in letterlike is sans-serif */
{UINT32_C(0xA4F5), (uint_least32_t)'U'},
{UINT32_C(0xA4E5), (uint_least32_t)'V'},
{UINT32_C(0x1D5A6), UINT32_C(0x2141)},
{UINT32_C(0x1D5AB), UINT32_C(0x2142)},
{UINT32_C(0x1D5B8), UINT32_C(0x2144)},
{UINT32_C(0x1F12F), UINT32_C(0x00A9)},
{UINT32_C(0x230C), UINT32_C(0x230F)},
{UINT32_C(0x230E), UINT32_C(0x230D)}
};
enum libcharconv_result
libcharconv_turned(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp)
{
uint_least32_t c;
size_t i, clen;
*n = 0;
while (slen) {
clen = libcharconv_decode_utf8_(s, slen, &c);
if (clen > slen) {
if (*n)
goto no_conv;
return LIBCHARCONV_INDETERMINATE;
}
if (!clen) {
*n += 1u;
slen -= 1u;
s = &s[1];
continue;
}
if (UINT32_C(0x1FA00) <= c && c <= UINT32_C(0x1FA1D)) {
c += 0x2Au;
goto conv;
} else if (UINT32_C(0x1FA2A) <= c && c <= UINT32_C(0x1FA47)) {
c -= 0x2Au;
goto conv;
} else if (UINT32_C(0x1FA1E) <= c && c <= UINT32_C(0x1FA29)) {
c -= UINT32_C(0x1FA1E) - UINT32_C(0x2654);
goto conv;
} else if (UINT32_C(0x2654) <= c && c <= UINT32_C(0x265F)) {
c += UINT32_C(0x1FA1E) - UINT32_C(0x2654);
goto conv;
} else if (UINT32_C(0x1F031) <= c && c <= UINT32_C(0x1F061)) {
c -= UINT32_C(0x1F031);
c = c % 7u * 7u + c / 7u;
c += UINT32_C(0x1F031);
goto conv;
} else if (UINT32_C(0x1F063) <= c && c <= UINT32_C(0x1F093)) {
c -= UINT32_C(0x1F063);
c = c % 7u * 7u + c / 7u;
c += UINT32_C(0x1F063);
goto conv;
} else {
for (i = 0u; i < sizeof(pairs) / sizeof(*pairs); i++) {
if (c == pairs[i].a) {
c = pairs[i].b;
goto conv;
}
if (c == pairs[i].b) {
c = pairs[i].a;
goto conv;
}
}
}
*n += clen;
s = &s[clen];
slen -= clen;
}
no_conv:
return LIBCHARCONV_NO_CONVERT;
conv:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += clen;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
}
|