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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/*
** Copyright 2011 Double Precision, Inc.
** See COPYING for distribution information.
**
*/
#include "unicode_config.h"
#include "courier-unicode.h"
#define BLOCK_SIZE 256
uint8_t unicode_tab_lookup(char32_t ch,
const size_t *unicode_starting_indextab,
const char32_t *unicode_starting_pagetab,
size_t unicode_tab_sizeof,
const uint8_t (*unicode_rangetab)[2],
size_t unicode_rangetab_sizeof,
const uint8_t *unicode_classtab,
uint8_t uclass)
{
size_t cl=ch / BLOCK_SIZE;
size_t b=0;
size_t e=unicode_tab_sizeof;
while (b < e)
{
size_t n=b + (e-b)/2;
if (cl < unicode_starting_indextab[n])
{
e=n;
continue;
}
else if (cl > unicode_starting_indextab[n])
{
b=n+1;
continue;
}
const size_t start_pos=unicode_starting_pagetab[n];
const uint8_t (*p)[2]=unicode_rangetab + start_pos;
b=0;
e=(n+1 >= unicode_tab_sizeof
? unicode_rangetab_sizeof
: unicode_starting_pagetab[n+1]) - start_pos;
uint8_t chmodcl= ch & (BLOCK_SIZE-1);
while (b < e)
{
size_t n=b + (e-b)/2;
if (chmodcl >= p[n][0])
{
if (chmodcl <= p[n][1])
{
uclass=unicode_classtab ?
unicode_classtab[start_pos+n]
: 1;
break;
}
b=n+1;
}
else
{
e=n;
}
}
break;
}
return uclass;
}
uint32_t unicode_tab32_lookup(char32_t ch,
const size_t *unicode_starting_indextab,
const char32_t *unicode_starting_pagetab,
size_t unicode_tab_sizeof,
const uint8_t (*unicode_rangetab)[2],
size_t unicode_rangetab_sizeof,
const uint32_t *unicode_classtab,
uint32_t uclass)
{
size_t cl=ch / BLOCK_SIZE;
size_t b=0;
size_t e=unicode_tab_sizeof;
while (b < e)
{
size_t n=b + (e-b)/2;
if (cl < unicode_starting_indextab[n])
{
e=n;
continue;
}
else if (cl > unicode_starting_indextab[n])
{
b=n+1;
continue;
}
const size_t start_pos=unicode_starting_pagetab[n];
const uint8_t (*p)[2]=unicode_rangetab + start_pos;
b=0;
e=(n+1 >= unicode_tab_sizeof
? unicode_rangetab_sizeof
: unicode_starting_pagetab[n+1]) - start_pos;
uint8_t chmodcl= ch & (BLOCK_SIZE-1);
while (b < e)
{
size_t n=b + (e-b)/2;
if (chmodcl >= p[n][0])
{
if (chmodcl <= p[n][1])
{
uclass=unicode_classtab ?
unicode_classtab[start_pos+n]
: 1;
break;
}
b=n+1;
}
else
{
e=n;
}
}
break;
}
return uclass;
}
|