The expression "x in dict" is now a maybe type
[delight/core.git] / dmd / unialpha.c
blobffc4ad7ac64625d8bb368e418ff715932b258db3
2 // Copyright (c) 2003 by Digital Mars
3 // All Rights Reserved
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
10 #include <assert.h>
12 /*******************************
13 * Return !=0 if unicode alpha.
14 * Use table from C99 Appendix D.
17 int isUniAlpha(unsigned u)
19 static unsigned short table[][2] =
21 { 0x00AA, 0x00AA },
22 { 0x00B5, 0x00B5 },
23 { 0x00B7, 0x00B7 },
24 { 0x00BA, 0x00BA },
25 { 0x00C0, 0x00D6 },
26 { 0x00D8, 0x00F6 },
27 { 0x00F8, 0x01F5 },
28 { 0x01FA, 0x0217 },
29 { 0x0250, 0x02A8 },
30 { 0x02B0, 0x02B8 },
31 { 0x02BB, 0x02BB },
32 { 0x02BD, 0x02C1 },
33 { 0x02D0, 0x02D1 },
34 { 0x02E0, 0x02E4 },
35 { 0x037A, 0x037A },
36 { 0x0386, 0x0386 },
37 { 0x0388, 0x038A },
38 { 0x038C, 0x038C },
39 { 0x038E, 0x03A1 },
40 { 0x03A3, 0x03CE },
41 { 0x03D0, 0x03D6 },
42 { 0x03DA, 0x03DA },
43 { 0x03DC, 0x03DC },
44 { 0x03DE, 0x03DE },
45 { 0x03E0, 0x03E0 },
46 { 0x03E2, 0x03F3 },
47 { 0x0401, 0x040C },
48 { 0x040E, 0x044F },
49 { 0x0451, 0x045C },
50 { 0x045E, 0x0481 },
51 { 0x0490, 0x04C4 },
52 { 0x04C7, 0x04C8 },
53 { 0x04CB, 0x04CC },
54 { 0x04D0, 0x04EB },
55 { 0x04EE, 0x04F5 },
56 { 0x04F8, 0x04F9 },
57 { 0x0531, 0x0556 },
58 { 0x0559, 0x0559 },
59 { 0x0561, 0x0587 },
60 { 0x05B0, 0x05B9 },
61 { 0x05BB, 0x05BD },
62 { 0x05BF, 0x05BF },
63 { 0x05C1, 0x05C2 },
64 { 0x05D0, 0x05EA },
65 { 0x05F0, 0x05F2 },
66 { 0x0621, 0x063A },
67 { 0x0640, 0x0652 },
68 { 0x0660, 0x0669 },
69 { 0x0670, 0x06B7 },
70 { 0x06BA, 0x06BE },
71 { 0x06C0, 0x06CE },
72 { 0x06D0, 0x06DC },
73 { 0x06E5, 0x06E8 },
74 { 0x06EA, 0x06ED },
75 { 0x06F0, 0x06F9 },
76 { 0x0901, 0x0903 },
77 { 0x0905, 0x0939 },
78 { 0x093D, 0x093D },
79 { 0x093E, 0x094D },
80 { 0x0950, 0x0952 },
81 { 0x0958, 0x0963 },
82 { 0x0966, 0x096F },
83 { 0x0981, 0x0983 },
84 { 0x0985, 0x098C },
85 { 0x098F, 0x0990 },
86 { 0x0993, 0x09A8 },
87 { 0x09AA, 0x09B0 },
88 { 0x09B2, 0x09B2 },
89 { 0x09B6, 0x09B9 },
90 { 0x09BE, 0x09C4 },
91 { 0x09C7, 0x09C8 },
92 { 0x09CB, 0x09CD },
93 { 0x09DC, 0x09DD },
94 { 0x09DF, 0x09E3 },
95 { 0x09E6, 0x09EF },
96 { 0x09F0, 0x09F1 },
97 { 0x0A02, 0x0A02 },
98 { 0x0A05, 0x0A0A },
99 { 0x0A0F, 0x0A10 },
100 { 0x0A13, 0x0A28 },
101 { 0x0A2A, 0x0A30 },
102 { 0x0A32, 0x0A33 },
103 { 0x0A35, 0x0A36 },
104 { 0x0A38, 0x0A39 },
105 { 0x0A3E, 0x0A42 },
106 { 0x0A47, 0x0A48 },
107 { 0x0A4B, 0x0A4D },
108 { 0x0A59, 0x0A5C },
109 { 0x0A5E, 0x0A5E },
110 { 0x0A66, 0x0A6F },
111 { 0x0A74, 0x0A74 },
112 { 0x0A81, 0x0A83 },
113 { 0x0A85, 0x0A8B },
114 { 0x0A8D, 0x0A8D },
115 { 0x0A8F, 0x0A91 },
116 { 0x0A93, 0x0AA8 },
117 { 0x0AAA, 0x0AB0 },
118 { 0x0AB2, 0x0AB3 },
119 { 0x0AB5, 0x0AB9 },
120 { 0x0ABD, 0x0AC5 },
121 { 0x0AC7, 0x0AC9 },
122 { 0x0ACB, 0x0ACD },
123 { 0x0AD0, 0x0AD0 },
124 { 0x0AE0, 0x0AE0 },
125 { 0x0AE6, 0x0AEF },
126 { 0x0B01, 0x0B03 },
127 { 0x0B05, 0x0B0C },
128 { 0x0B0F, 0x0B10 },
129 { 0x0B13, 0x0B28 },
130 { 0x0B2A, 0x0B30 },
131 { 0x0B32, 0x0B33 },
132 { 0x0B36, 0x0B39 },
133 { 0x0B3D, 0x0B3D },
134 { 0x0B3E, 0x0B43 },
135 { 0x0B47, 0x0B48 },
136 { 0x0B4B, 0x0B4D },
137 { 0x0B5C, 0x0B5D },
138 { 0x0B5F, 0x0B61 },
139 { 0x0B66, 0x0B6F },
140 { 0x0B82, 0x0B83 },
141 { 0x0B85, 0x0B8A },
142 { 0x0B8E, 0x0B90 },
143 { 0x0B92, 0x0B95 },
144 { 0x0B99, 0x0B9A },
145 { 0x0B9C, 0x0B9C },
146 { 0x0B9E, 0x0B9F },
147 { 0x0BA3, 0x0BA4 },
148 { 0x0BA8, 0x0BAA },
149 { 0x0BAE, 0x0BB5 },
150 { 0x0BB7, 0x0BB9 },
151 { 0x0BBE, 0x0BC2 },
152 { 0x0BC6, 0x0BC8 },
153 { 0x0BCA, 0x0BCD },
154 { 0x0BE7, 0x0BEF },
155 { 0x0C01, 0x0C03 },
156 { 0x0C05, 0x0C0C },
157 { 0x0C0E, 0x0C10 },
158 { 0x0C12, 0x0C28 },
159 { 0x0C2A, 0x0C33 },
160 { 0x0C35, 0x0C39 },
161 { 0x0C3E, 0x0C44 },
162 { 0x0C46, 0x0C48 },
163 { 0x0C4A, 0x0C4D },
164 { 0x0C60, 0x0C61 },
165 { 0x0C66, 0x0C6F },
166 { 0x0C82, 0x0C83 },
167 { 0x0C85, 0x0C8C },
168 { 0x0C8E, 0x0C90 },
169 { 0x0C92, 0x0CA8 },
170 { 0x0CAA, 0x0CB3 },
171 { 0x0CB5, 0x0CB9 },
172 { 0x0CBE, 0x0CC4 },
173 { 0x0CC6, 0x0CC8 },
174 { 0x0CCA, 0x0CCD },
175 { 0x0CDE, 0x0CDE },
176 { 0x0CE0, 0x0CE1 },
177 { 0x0CE6, 0x0CEF },
178 { 0x0D02, 0x0D03 },
179 { 0x0D05, 0x0D0C },
180 { 0x0D0E, 0x0D10 },
181 { 0x0D12, 0x0D28 },
182 { 0x0D2A, 0x0D39 },
183 { 0x0D3E, 0x0D43 },
184 { 0x0D46, 0x0D48 },
185 { 0x0D4A, 0x0D4D },
186 { 0x0D60, 0x0D61 },
187 { 0x0D66, 0x0D6F },
188 { 0x0E01, 0x0E3A },
189 { 0x0E40, 0x0E5B },
190 // { 0x0E50, 0x0E59 },
191 { 0x0E81, 0x0E82 },
192 { 0x0E84, 0x0E84 },
193 { 0x0E87, 0x0E88 },
194 { 0x0E8A, 0x0E8A },
195 { 0x0E8D, 0x0E8D },
196 { 0x0E94, 0x0E97 },
197 { 0x0E99, 0x0E9F },
198 { 0x0EA1, 0x0EA3 },
199 { 0x0EA5, 0x0EA5 },
200 { 0x0EA7, 0x0EA7 },
201 { 0x0EAA, 0x0EAB },
202 { 0x0EAD, 0x0EAE },
203 { 0x0EB0, 0x0EB9 },
204 { 0x0EBB, 0x0EBD },
205 { 0x0EC0, 0x0EC4 },
206 { 0x0EC6, 0x0EC6 },
207 { 0x0EC8, 0x0ECD },
208 { 0x0ED0, 0x0ED9 },
209 { 0x0EDC, 0x0EDD },
210 { 0x0F00, 0x0F00 },
211 { 0x0F18, 0x0F19 },
212 { 0x0F20, 0x0F33 },
213 { 0x0F35, 0x0F35 },
214 { 0x0F37, 0x0F37 },
215 { 0x0F39, 0x0F39 },
216 { 0x0F3E, 0x0F47 },
217 { 0x0F49, 0x0F69 },
218 { 0x0F71, 0x0F84 },
219 { 0x0F86, 0x0F8B },
220 { 0x0F90, 0x0F95 },
221 { 0x0F97, 0x0F97 },
222 { 0x0F99, 0x0FAD },
223 { 0x0FB1, 0x0FB7 },
224 { 0x0FB9, 0x0FB9 },
225 { 0x10A0, 0x10C5 },
226 { 0x10D0, 0x10F6 },
227 { 0x1E00, 0x1E9B },
228 { 0x1EA0, 0x1EF9 },
229 { 0x1F00, 0x1F15 },
230 { 0x1F18, 0x1F1D },
231 { 0x1F20, 0x1F45 },
232 { 0x1F48, 0x1F4D },
233 { 0x1F50, 0x1F57 },
234 { 0x1F59, 0x1F59 },
235 { 0x1F5B, 0x1F5B },
236 { 0x1F5D, 0x1F5D },
237 { 0x1F5F, 0x1F7D },
238 { 0x1F80, 0x1FB4 },
239 { 0x1FB6, 0x1FBC },
240 { 0x1FBE, 0x1FBE },
241 { 0x1FC2, 0x1FC4 },
242 { 0x1FC6, 0x1FCC },
243 { 0x1FD0, 0x1FD3 },
244 { 0x1FD6, 0x1FDB },
245 { 0x1FE0, 0x1FEC },
246 { 0x1FF2, 0x1FF4 },
247 { 0x1FF6, 0x1FFC },
248 { 0x203F, 0x2040 },
249 { 0x207F, 0x207F },
250 { 0x2102, 0x2102 },
251 { 0x2107, 0x2107 },
252 { 0x210A, 0x2113 },
253 { 0x2115, 0x2115 },
254 { 0x2118, 0x211D },
255 { 0x2124, 0x2124 },
256 { 0x2126, 0x2126 },
257 { 0x2128, 0x2128 },
258 { 0x212A, 0x2131 },
259 { 0x2133, 0x2138 },
260 { 0x2160, 0x2182 },
261 { 0x3005, 0x3007 },
262 { 0x3021, 0x3029 },
263 { 0x3041, 0x3093 },
264 { 0x309B, 0x309C },
265 { 0x30A1, 0x30F6 },
266 { 0x30FB, 0x30FC },
267 { 0x3105, 0x312C },
268 { 0x4E00, 0x9FA5 },
269 { 0xAC00, 0xD7A3 },
272 #ifdef DEBUG
273 for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
275 //printf("%x\n", table[i][0]);
276 assert(table[i][0] <= table[i][1]);
277 if (i < sizeof(table) / sizeof(table[0]) - 1)
278 assert(table[i][1] < table[i + 1][0]);
280 #endif
282 if (u > 0xD7A3)
283 goto Lisnot;
285 // Binary search
286 int mid;
287 int low;
288 int high;
290 low = 0;
291 high = sizeof(table) / sizeof(table[0]) - 1;
292 while (low <= high)
294 mid = (low + high) >> 1;
295 if (u < table[mid][0])
296 high = mid - 1;
297 else if (u > table[mid][1])
298 low = mid + 1;
299 else
300 goto Lis;
303 Lisnot:
304 #ifdef DEBUG
305 for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
307 assert(u < table[i][0] || u > table[i][1]);
309 #endif
310 return 0;
312 Lis:
313 #ifdef DEBUG
314 for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++)
316 if (u >= table[i][0] && u <= table[i][1])
317 return 1;
319 assert(0); // should have been in table
320 #endif
321 return 1;