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


static struct {
	unsigned char cp_low;
	char latin;
} sora_sompeng[] = {
	{0xE2, 'a'},
	{0xD2, 'b'},
	{0xD3, 'c'},
	{0xD4, 'd'},
	{0xE7, 'e'},
	{0xE3, 'E'},
	{0xD5, 'g'},
	{0xD7, 'G'},
	{0xDE, 'h'},
	{0xE4, 'i'},
	{0xE0, 'j'},
	{0xDF, 'k'},
	{0xD8, 'l'},
	{0xD9, 'n'},
	{0xD6, 'm'},
	{0xE8, 'M'},
	{0xE6, 'o'},
	{0xDB, 'p'},
	{0xDD, 'r'},
	{0xD0, 's'},
	{0xD1, 't'},
	{0xE5, 'u'},
	{0xDA, 'v'},
	{0xDC, 'y'},
	{0xE1, 'Y'},
	{0xF0, '0'},
	{0xF1, '1'},
	{0xF2, '2'},
	{0xF3, '3'},
	{0xF4, '4'},
	{0xF5, '5'},
	{0xF6, '6'},
	{0xF7, '7'},
	{0xF8, '8'},
	{0xF9, '9'}
};


enum libcharconv_result
libcharconv_sora_sompeng(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(sora_sompeng) / sizeof(*sora_sompeng); i++)
			if (*s == sora_sompeng[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(0x11000) | sora_sompeng[i].cp_low);
	*n += 1u;
	*ncp = 1u;
	return LIBCHARCONV_CONVERTED;
}