aboutsummaryrefslogtreecommitdiffstats
path: root/libcharconv_symbols.c
blob: c1a4459ce2d503de10b01f15cb66f1152f698d71 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* See LICENSE file for copyright and license details. */
#include "lib-common.h"


static struct {
	uint_least32_t cp;
	const char *s;
} symbols[] = {
	{UINT32_C(0x269E), "->"},
	{UINT32_C(0x269F), "<-"},
	{UINT32_C(0x2120), "SM"},
	{UINT32_C(0x2122), "TM"},
	{UINT32_C(0x00A9), "(C)"},
	{UINT32_C(0x1F1AD), "(M)"},
	{UINT32_C(0x2117), "(P)"},
	{UINT32_C(0x00AE), "(R)"},
	{UINT32_C(0x1F10D), "(0)"},
	{UINT32_C(0x1F10F), "\\($)"},
	{UINT32_C(0x1F10F), "(\\$)"},
	{UINT32_C(0x1F10F), "($\\)"},
	{UINT32_C(0x1F10F), "($)\\"},
	{UINT32_C(0x1F16E), "\\(C)"},
	{UINT32_C(0x1F16E), "(\\C)"},
	{UINT32_C(0x1F16E), "(C\\)"},
	{UINT32_C(0x1F16E), "(C)\\"},
	{UINT32_C(0x1F16D), "(CC)"},
	{UINT32_C(0x212E), "e"},
	{UINT32_C(0x2139), "i"},
	{UINT32_C(0x212A), "K"},
	{UINT32_C(0x213B), "FAX"},
	{UINT32_C(0x213B), "Fax"},
	{UINT32_C(0x2121), "TEL"},
	{UINT32_C(0x2121), "Tel"},
	{UINT32_C(0x212B), "A"},
	{UINT32_C(0x2100), "ac"},
	{UINT32_C(0x2100), "a/c"},
	{UINT32_C(0x214D), "AS"},
	{UINT32_C(0x214D), "A/S"},
	{UINT32_C(0x2101), "as"},
	{UINT32_C(0x2101), "a/s"},
	{UINT32_C(0x00AA), "a"},
	{UINT32_C(0x00BA), "o"},
	{UINT32_C(0x2300), "/o"},
	{UINT32_C(0x2300), "o/"},
	{UINT32_C(0x2116), "No"},
	{UINT32_C(0x2118), "p"},
	{UINT32_C(0x2118), "P"},
	{UINT32_C(0x214A), "PL"},
	{UINT32_C(0x211E), "Px"},
	{UINT32_C(0x211F), "R/"},
	{UINT32_C(0x211F), "/R"},
	{UINT32_C(0x2123), "V/"},
	{UINT32_C(0x2123), "/V"},
	{UINT32_C(0x2125), "z"},
	{UINT32_C(0x23E8), "10"},
	{UINT32_C(0x2104), "CL"},
	{UINT32_C(0x2105), "c/o"},
	{UINT32_C(0x2105), "co"},
	{UINT32_C(0x2105), "C/O"},
	{UINT32_C(0x2105), "CO"},
	{UINT32_C(0x2106), "c/u"},
	{UINT32_C(0x2106), "cu"},
	{UINT32_C(0x2106), "C/U"},
	{UINT32_C(0x2106), "CU"},
	{UINT32_C(0x2113), "l"},
	{UINT32_C(0x2114), "lb"},
	{UINT32_C(0x1F19B), "[3D]"},
	{UINT32_C(0x1F19B), "3D"},
	{UINT32_C(0x1F19C), "[2ND SCR]"},
	{UINT32_C(0x1F19C), "2ND SCR"},
	{UINT32_C(0x1F1A7), "[HDR]"},
	{UINT32_C(0x1F1A7), "HDR"},
	{UINT32_C(0x1F1A6), "[HC]"},
	{UINT32_C(0x1F1A6), "HC"},
	{UINT32_C(0x1F1AC), "[VOD]"},
	{UINT32_C(0x1F1AC), "VOD"},
	{UINT32_C(0x1F1A3), "[60P]"},
	{UINT32_C(0x1F1A3), "60P"},
	{UINT32_C(0x1F1A8), "[HI-RES]"},
	{UINT32_C(0x1F1A8), "HI-RES"},
	{UINT32_C(0x1F1A4), "[120P]"},
	{UINT32_C(0x1F1A4), "120P"},
	{UINT32_C(0x1F19D), "[2K]"},
	{UINT32_C(0x1F19D), "2K"},
	{UINT32_C(0x1F19E), "[4K]"},
	{UINT32_C(0x1F19E), "4K"},
	{UINT32_C(0x1F19F), "[8K]"},
	{UINT32_C(0x1F19F), "8K"},
	{UINT32_C(0x1F1AB), "[UHD]"},
	{UINT32_C(0x1F1AB), "UHD"},
	{UINT32_C(0x1F1AA), "[SHV]"},
	{UINT32_C(0x1F1AA), "SHV"},
	{UINT32_C(0x1F1A9), "[LOSSLESS]"},
	{UINT32_C(0x1F1A9), "LOSSLESS"},
	{UINT32_C(0x1F1A0), "[5.1]"},
	{UINT32_C(0x1F1A0), "5.1"},
	{UINT32_C(0x1F1A1), "[7.1]"},
	{UINT32_C(0x1F1A1), "7.1"},
	{UINT32_C(0x1F1A2), "[22.2]"},
	{UINT32_C(0x1F1A2), "22.2"},
	{UINT32_C(0x2141), "G"},
	{UINT32_C(0x2142), "L"},
	{UINT32_C(0x2144), "Y"}
};


enum libcharconv_result
libcharconv_symbols(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp)
{
	size_t i, len, found, found_len;
	int indeterminate;
	*n = 0;
	for (; slen; s++, slen--, ++*n) {
		indeterminate = 0;
		found = SIZE_MAX;
		found_len = 0u;
		for (i = 0u; i < sizeof(symbols) / sizeof(*symbols); i++) {
			len = strlen(symbols[i].s);
			if (strncmp(s, symbols[i].s, len < slen ? len : slen))
				continue;
			if (slen < len) {
				indeterminate = 1;
				continue;
			}
			if (len > found_len) {
				found = i;
				found_len = len;
			}
		}
		if (found_len)
			goto conv;
		if (*n)
			goto no_conv;
		if (indeterminate)
			return LIBCHARCONV_INDETERMINATE;
	}
no_conv:
	return LIBCHARCONV_NO_CONVERT;

conv:
	if (*n)
		goto no_conv;
	if (*ncp)
		*cp = symbols[found].cp;
	*n += found_len;
	*ncp = 1u;
	return indeterminate ? LIBCHARCONV_CONVERT_IF_END : LIBCHARCONV_CONVERTED;
}