blob: 285c10de46a264e316b5bf9f29230e5bdd64e9b9 (
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
|
/* See LICENSE file for copyright and license details. */
#include "lib-common.h"
enum libcharconv_result
libcharconv_vulgar_fractions(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++) {
if (s[0] == '/') {
if (*n)
goto no_conv;
c = UINT32_C(0x2044);
*n = 1u;
goto conv;
} else if (('0' <= s[0] && s[0] <= '5') || s[0] <= '7') {
if (*n)
goto no_conv;
if (slen == 0u)
return LIBCHARCONV_INDETERMINATE;
if (s[1] != '/')
goto no_match;
if (slen == 1u) {
if (s[0] == '1') {
c = UINT32_C(0x215F);
*n = 2u;
if (*ncp)
*cp = c;
*ncp = 1u;
return LIBCHARCONV_CONVERT_IF_END;
} else {
return LIBCHARCONV_INDETERMINATE;
}
}
if (s[0] == '0' && s[2] == '3') { c = UINT32_C(0x2189);
} else if (s[0] == '2' && s[2] == '3') { c = UINT32_C(0x2154);
} else if (s[0] == '2' && s[2] == '5') { c = UINT32_C(0x2156);
} else if (s[0] == '3' && s[2] == '4') { c = UINT32_C(0x00BE);
} else if (s[0] == '3' && s[2] == '5') { c = UINT32_C(0x2157);
} else if (s[0] == '3' && s[2] == '8') { c = UINT32_C(0x215C);
} else if (s[0] == '4' && s[2] == '5') { c = UINT32_C(0x2158);
} else if (s[0] == '5' && s[2] == '6') { c = UINT32_C(0x215A);
} else if (s[0] == '5' && s[2] == '8') { c = UINT32_C(0x215D);
} else if (s[0] == '7' && s[2] == '8') { c = UINT32_C(0x215E);
} else if (s[0] == '1' && s[2] == '2') { c = UINT32_C(0x00BD);
} else if (s[0] == '1' && s[2] == '3') { c = UINT32_C(0x2153);
} else if (s[0] == '1' && s[2] == '4') { c = UINT32_C(0x00BC);
} else if (s[0] == '1' && s[2] == '5') { c = UINT32_C(0x2155);
} else if (s[0] == '1' && s[2] == '6') { c = UINT32_C(0x2159);
} else if (s[0] == '1' && s[2] == '7') { c = UINT32_C(0x2150);
} else if (s[0] == '1' && s[2] == '8') { c = UINT32_C(0x215B);
} else if (s[0] == '1' && s[2] == '9') { c = UINT32_C(0x2151);
} else if (s[0] == '1' && s[2] == '1') {
if (slen == 2u)
return LIBCHARCONV_INDETERMINATE;
if (s[3] == '0') {
c = UINT32_C(0x2152);
*n = 4u;
if (*ncp)
*cp = c;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
} else {
goto denum_1;
}
} else if (s[0] == '1') {
denum_1:
*n = 2u;
c = UINT32_C(0x215F);
goto conv;
} else {
goto no_match;
}
*n = 3u;
goto conv;
} else {
no_match:
*n += 1u;
}
}
no_conv:
return LIBCHARCONV_NO_CONVERT;
conv:
if (*ncp)
*cp = c;
*ncp = 1u;
return LIBCHARCONV_CONVERTED;
}
|