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


static struct {
	unsigned char cp_low;
	char latin;
} mandaic[] = {
	{0x40, 'a'},
	{0x41, 'b'},
	{0x42, 'g'},
	{0x43, 'd'},
	{0x44, 'h'},
	{0x45, 'u'},
	{0x45, 'w'},
	{0x46, 'z'},
	{0x47, 'H'},
	{0x48, 'T'},
	{0x49, 'j'},
	{0x49, 'j'},
	{0x4A, 'k'},
	{0x4B, 'l'},
	{0x4C, 'm'},
	{0x4D, 'n'},
	{0x4E, 's'},
	{0x4F, 'e'},
	{0x50, 'p'},
	{0x51, 'Z'},
	{0x52, 'q'},
	{0x53, 'r'},
	{0x54, 'S'},
	{0x55, 't'},
	{0x56, 'D'},
	{0x57, 'K'},
	{0x58, 'o'},
	{0x59, '\''},
	{0x5A, '*'},
	{0x5B, ':'},
	{0x5E, '.'}
};


enum libcharconv_result
libcharconv_mandaic(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(mandaic) / sizeof(*mandaic); i++)
			if (*s == mandaic[i].latin)
					goto conv;
		*n += 1u;
	}
no_conv:
	return LIBCHARCONV_NO_CONVERT;

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