summaryrefslogtreecommitdiffstats
path: root/unicode/unicode_ultcase.c
blob: 3ddd9e315cfd1c83d5892420874aec5971785647 (plain)
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
/*
** Copyright 2000-2003 Double Precision, Inc.
** See COPYING for distribution information.
**
*/

#include "unicode_config.h"
#include "courier-unicode.h"

extern const unsigned unicode_case_hash;
extern const char32_t unicode_case_tab[][4];
extern const unsigned unicode_case_offset[];

static unsigned find_case(char32_t c)
{
	unsigned idx= c % unicode_case_hash;

	unsigned i=unicode_case_offset[idx];

	char32_t uc;

	--i;

	do
	{
		uc=unicode_case_tab[++i][0];
		if (uc == c)
			return (i);
	} while ( (uc % unicode_case_hash) == idx);

	return (0);
}

char32_t unicode_uc(char32_t c)
{
	unsigned i=find_case(c);

	return (unicode_case_tab[i][0] != c ? c:unicode_case_tab[i][1]);
}

char32_t unicode_lc(char32_t c)
{
	unsigned i=find_case(c);

	return (unicode_case_tab[i][0] != c ? c:unicode_case_tab[i][2]);
}

char32_t unicode_tc(char32_t c)
{
	unsigned i;
	char32_t oc=c;

	c=unicode_lc(c);
	i=find_case(c);

	return (unicode_case_tab[i][0] != c ? oc:unicode_case_tab[i][3]);
}