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


enum libcharconv_result
libcharconv_dentistry(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++) {
		switch (*s) {
		case 'o':
		case 'O': c = UINT32_C(0x23C0); goto conv;
		case 'a':
		case 'A': c = UINT32_C(0x23C3); goto conv;
		case '~': c = UINT32_C(0x23C6); goto conv;
		case 'l': c = UINT32_C(0x23BF); goto conv;
		case 'j': c = UINT32_C(0x23CC); goto conv;
		case 't': c = UINT32_C(0x23CA); goto conv;
		case 'L': c = UINT32_C(0x23BE); goto conv;
		case 'J': c = UINT32_C(0x23CB); goto conv;
		case 'T': c = UINT32_C(0x23C9); goto conv;
		case '-':
		case '_':
			if (!slen)
				return LIBCHARCONV_INDETERMINATE;
			if (s[1] != 'A' && s[1] != 'O' && s[1] != '~')
				if (s[1] != 'a' && s[1] != 'o')
					goto no_match;
			c = (s[1] == 'A' || s[1] == 'a') ? UINT32_C(0x23C1) :
			    (s[1] == 'O' || s[1] == 'o') ? UINT32_C(0x23C4) : UINT32_C(0x23C7);
			if (s[0] == '_')
				c += 1u;
			goto conv2;
		default:
		no_match:
			*n += 1u;
			break;
		}
	}
no_conv:
	return LIBCHARCONV_NO_CONVERT;

conv:
	if (*n)
		goto no_conv;
	if (*ncp)
		*cp = c;
	*n += 1u;
	*ncp = 1u;
	return LIBCHARCONV_CONVERTED;

conv2:
	if (*n)
		goto no_conv;
	if (*ncp)
		*cp = c;
	*n += 2u;
	*ncp = 1u;
	return LIBCHARCONV_CONVERTED;
}