aboutsummaryrefslogtreecommitdiffstats
path: root/libcharconv_lycian.c
blob: 7998ecb69521d43d0f1aad4cccb4bfcfd5700922 (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
/* See LICENSE file for copyright and license details. */
#include "lib-common.h"


static struct {
	unsigned char cp_low;
	char latin;
} lycian[] = {
	{0x80, 'a'},
	{0x82, 'b'},
	{0x85, 'd'},
	{0x81, 'e'},
	{0x84, 'g'},
	{0x9B, 'h'},
	{0x86, 'i'},
	{0x8A, 'j'},
	{0x8B, 'k'},
	{0x8D, 'l'},
	{0x8E, 'm'},
	{0x8F, 'n'},
	{0x93, 'p'},
	{0x8C, 'q'},
	{0x95, 'r'},
	{0x96, 's'},
	{0x97, 't'},
	{0x92, 'u'},
	{0x87, 'w'},
	{0x9C, 'x'},
	{0x88, 'z'},
	{0x99, 'A'},
	{0x83, 'B'},
	{0x89, 'D'},
	{0x9A, 'E'},
	{0x94, 'K'},
	{0x90, 'M'},
	{0x91, 'N'},
	{0x98, 'T'}
};


enum libcharconv_result
libcharconv_lycian(const char *s, size_t slen, size_t *n, uint_least32_t *cp, size_t *ncp)
{
	size_t i;
	*n = 0;
	for (; slen--; s++) {
		for (i = 0u; i < sizeof(lycian) / sizeof(*lycian); i++)
			if (*s == lycian[i].latin)
				goto conv;
		*n += 1u;
	}
no_conv:
	return LIBCHARCONV_NO_CONVERT;

conv:
	if (*n)
		goto no_conv;
	if (*ncp)
		*cp = (uint_least32_t)(UINT32_C(0x10200) | lycian[i].cp_low);
	*n += 1u;
	*ncp = 1u;
	return LIBCHARCONV_CONVERTED;
}