blob: 787d14b21c9c96a7437108257803da5fb32f0f62 (
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
|
/* See LICENSE file for copyright and license details. */
#include "lib-common.h"
enum libcharconv_result
libcharconv_sans_serif(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 ('A' <= *s && *s <= 'Z') {
c = (uint_least32_t)(UINT32_C(0x1D5A0) + (unsigned)(*s - 'A'));
goto conv;
} else if ('a' <= *s && *s <= 'z') {
c = (uint_least32_t)(UINT32_C(0x1D5BA) + (unsigned)(*s - 'a'));
goto conv;
} else if ('0' <= *s && *s <= '9') {
c = (uint_least32_t)(UINT32_C(0x1D7E2) + (unsigned)(*s - '0'));
goto conv;
} else if ((unsigned char)s[0] == 0xE2u) {
if (!slen--)
goto indeterminate;
if ((unsigned char)s[1] == 0x93u) {
if (!slen--)
goto indeterminate;
if ((unsigned char)s[2] == 0xAAu)
c = (uint_least32_t)UINT32_C(0x1F10B);
else if ((unsigned char)s[2] == 0xBFu)
c = (uint_least32_t)UINT32_C(0x1F10C);
else
goto no_match;
goto conv3;
} else if ((unsigned char)s[1] == 0x91u) {
if (!slen--)
goto indeterminate;
if (0xA0u <= (unsigned char)s[2] && (unsigned char)s[2] <= 0xA9u)
c = (uint_least32_t)UINT32_C(0x2780);
else
goto no_match;
c += (unsigned char)s[2] - 0xA0u;
goto conv3;
} else if ((unsigned char)s[1] == 0x9Du) {
if (!slen--)
goto indeterminate;
if (!slen--)
goto indeterminate;
if (0xB6u <= (unsigned char)s[2] && (unsigned char)s[2] <= 0xBFu)
c = (uint_least32_t)UINT32_C(0x278A);
else
goto no_match;
c += (unsigned char)s[2] - 0xB6u;
goto conv3;
} else {
goto no_match;
}
} else {
no_match:
slen = old_slen;
*n += 1u;
}
}
no_conv:
return LIBCHARCONV_NO_CONVERT;
indeterminate:
return LIBCHARCONV_INDETERMINATE;
conv:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 1u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
conv3:
if (*n)
goto no_conv;
if (*ncp)
*cp = c;
*n += 3u;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
}
|