aboutsummaryrefslogtreecommitdiff
path: root/lib/unicode/prop/uprop_get_lc.c
blob: faf26c3771d55be9246c08c6b00ea25c7e0de526 (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
#include "macros.h"
#include "unicode/prop.h"

#define M(...) ((struct rview)_(__VA_ARGS__))
#define _(...) \
	{(const rune[]){__VA_ARGS__}, lengthof(((const rune[]){__VA_ARGS__}))}

struct rview
uprop_get_lc(rune ch, struct lcctx ctx)
{
	constexpr rune COMB_GRAVE     = 0x300;
	constexpr rune COMB_ACUTE     = 0x301;
	constexpr rune COMB_TILDE     = 0x303;
	constexpr rune COMB_DOT_ABOVE = 0x307;

	if (ch == U'Σ')
		return ctx.final_sigma ? M(U'ς') : M(U'σ');
	if (ch == U'İ')
		return ctx.az_or_tr ? M('i') : M('i', COMB_DOT_ABOVE);

	if (ctx.lt) {
		if (ctx.more_above) {
			switch (ch) {
			case 'I':
				return M('i', COMB_DOT_ABOVE);
			case 'J':
				return M('j', COMB_DOT_ABOVE);
			case U'Į':
				return M(U'į', COMB_DOT_ABOVE);
			}
		}

		switch (ch) {
		case U'Ì':
			return M('i', COMB_DOT_ABOVE, COMB_GRAVE);
		case U'Í':
			return M('i', COMB_DOT_ABOVE, COMB_ACUTE);
		case U'Ĩ':
			return M('i', COMB_DOT_ABOVE, COMB_TILDE);
		}
	}

	if (ctx.az_or_tr) {
		if (ch == COMB_DOT_ABOVE && ctx.after_I)
			return M();
		if (ch == 'I' && !ctx.before_dot)
			return M(U'ı');
	}

	/* TODO: This returns a pointer to a stack-allocated array; fix this! */
	ch = uprop_get_slc(ch);
	return M(ch);
}