/
utf-ctype.c
141 lines (107 loc) · 2.37 KB
/
utf-ctype.c
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
137
138
139
140
141
/*
* utf-ctype.c
*
* Invoke libucd to test for specific character classes.
*/
#include "config.h"
#include "ucd.h"
#include "my-ctype.h"
int my_tolower(int x)
{
const struct unicode_character_data *ucd;
int rv;
ucd = unicode_character_data(x);
if (!ucd)
return x;
rv = ucd->simple_lowercase;
unicode_character_put(ucd);
return rv;
}
int my_toupper(int x)
{
const struct unicode_character_data *ucd;
int rv;
ucd = unicode_character_data(x);
if (!ucd)
return x;
rv = ucd->simple_uppercase;
unicode_character_put(ucd);
return rv;
}
int my_isdigit(int x)
{
const struct unicode_character_data *ucd;
int rv;
ucd = unicode_character_data(x);
if (!ucd)
return 0;
rv = ucd->numeric_type == UC_NT_Decimal;
unicode_character_put(ucd);
return rv;
}
int my_digitval(int x)
{
const struct unicode_character_data *ucd;
int rv;
ucd = unicode_character_data(x);
if (!ucd || ucd->numeric_type != UC_NT_Decimal)
return 0;
/* For digits, den == exp == 1 */
rv = ucd->numeric_value_num;
unicode_character_put(ucd);
return rv;
}
int my_isspace(int x)
{
const struct unicode_character_data *ucd;
int rv;
ucd = unicode_character_data(x);
if (!ucd)
return x;
rv = !!(ucd->fl & UC_FL_WHITE_SPACE);
unicode_character_put(ucd);
return rv;
}
/*
* The XID categories are the best thing in Unicode to what
* characters should allow to begin and continue identifiers,
* respectively.
*/
int my_is_xid_start(int x)
{
const struct unicode_character_data *ucd;
int rv;
ucd = unicode_character_data(x);
if (!ucd)
return 0;
rv = !!(ucd->fl & UC_FL_XID_START);
unicode_character_put(ucd);
return rv;
}
int my_is_xid_cont(int x)
{
const struct unicode_character_data *ucd;
int rv;
ucd = unicode_character_data(x);
if (!ucd)
return 0;
rv = !!(ucd->fl & UC_FL_XID_CONTINUE);
unicode_character_put(ucd);
return rv;
}
int my_is_printable(int x)
{
const struct unicode_character_data *ucd;
int rv;
if (x == 0x09)
return 1;
if ((x <= 0xff && ((x & 0x60) == 0x00 || x == 0x7f)) ||
(x >= 0xd800 && x <= 0xdfff))
return 0;
ucd = unicode_character_data(x);
if (!ucd)
return 0;
rv = !(ucd->fl & UC_FL_NONCHARACTER_CODE_POINT);
unicode_character_put(ucd);
return rv;
}