5 #define CASEMAP(u1,u2,l) { (u1), (l)-(u1), (u2)-(u1)+1 }
6 #define CASELACE(u1,u2) CASEMAP((u1),(u2),(u1)+1)
13 CASEMAP(0xc0,0xde,0xe0),
15 CASELACE(0x0100,0x012e),
16 CASELACE(0x0132,0x0136),
17 CASELACE(0x0139,0x0147),
18 CASELACE(0x014a,0x0176),
19 CASELACE(0x0179,0x017d),
21 CASELACE(0x370,0x372),
22 CASEMAP(0x391,0x3a1,0x3b1),
23 CASEMAP(0x3a3,0x3ab,0x3c3),
24 CASEMAP(0x400,0x40f,0x450),
25 CASEMAP(0x410,0x42f,0x430),
27 CASELACE(0x460,0x480),
28 CASELACE(0x48a,0x4be),
29 CASELACE(0x4c1,0x4cd),
30 CASELACE(0x4d0,0x50e),
32 CASELACE(0x514,0x52e),
33 CASEMAP(0x531,0x556,0x561),
35 CASELACE(0x01a0,0x01a4),
36 CASELACE(0x01b3,0x01b5),
37 CASELACE(0x01cd,0x01db),
38 CASELACE(0x01de,0x01ee),
39 CASELACE(0x01f8,0x021e),
40 CASELACE(0x0222,0x0232),
41 CASELACE(0x03d8,0x03ee),
43 CASELACE(0x1e00,0x1e94),
44 CASELACE(0x1ea0,0x1efe),
46 CASEMAP(0x1f08,0x1f0f,0x1f00),
47 CASEMAP(0x1f18,0x1f1d,0x1f10),
48 CASEMAP(0x1f28,0x1f2f,0x1f20),
49 CASEMAP(0x1f38,0x1f3f,0x1f30),
50 CASEMAP(0x1f48,0x1f4d,0x1f40),
52 CASEMAP(0x1f68,0x1f6f,0x1f60),
53 CASEMAP(0x1f88,0x1f8f,0x1f80),
54 CASEMAP(0x1f98,0x1f9f,0x1f90),
55 CASEMAP(0x1fa8,0x1faf,0x1fa0),
56 CASEMAP(0x1fb8,0x1fb9,0x1fb0),
57 CASEMAP(0x1fba,0x1fbb,0x1f70),
58 CASEMAP(0x1fc8,0x1fcb,0x1f72),
59 CASEMAP(0x1fd8,0x1fd9,0x1fd0),
60 CASEMAP(0x1fda,0x1fdb,0x1f76),
61 CASEMAP(0x1fe8,0x1fe9,0x1fe0),
62 CASEMAP(0x1fea,0x1feb,0x1f7a),
63 CASEMAP(0x1ff8,0x1ff9,0x1f78),
64 CASEMAP(0x1ffa,0x1ffb,0x1f7c),
66 CASEMAP(0x13f0,0x13f5,0x13f8),
67 CASELACE(0xa698,0xa69a),
68 CASELACE(0xa796,0xa79e),
70 CASELACE(0x246,0x24e),
71 CASELACE(0x510,0x512),
72 CASEMAP(0x2160,0x216f,0x2170),
73 CASEMAP(0x2c00,0x2c2e,0x2c30),
74 CASELACE(0x2c67,0x2c6b),
75 CASELACE(0x2c80,0x2ce2),
76 CASELACE(0x2ceb,0x2ced),
78 CASELACE(0xa640,0xa66c),
79 CASELACE(0xa680,0xa696),
81 CASELACE(0xa722,0xa72e),
82 CASELACE(0xa732,0xa76e),
83 CASELACE(0xa779,0xa77b),
84 CASELACE(0xa77e,0xa786),
86 CASELACE(0xa790,0xa792),
87 CASELACE(0xa7a0,0xa7a8),
89 CASELACE(0xa7b4,0xa7b6),
91 CASEMAP(0xff21,0xff3a,0xff41),
95 static const unsigned short pairs[][2] = {
213 /* bogus greek 'symbol' letters */
234 /* special cyrillic lowercase forms */
249 static wchar_t __towcase(wchar_t wc, int lower)
252 int lmul = 2*lower-1;
254 /* no letters with case in these large ranges */
256 || (unsigned)wc - 0x0600 <= 0x0fff-0x0600
257 || (unsigned)wc - 0x2e00 <= 0xa63f-0x2e00
258 || (unsigned)wc - 0xa800 <= 0xab52-0xa800
259 || (unsigned)wc - 0xabc0 <= 0xfeff-0xabc0)
261 /* special case because the diff between upper/lower is too big */
262 if (lower && (unsigned)wc - 0x10a0 < 0x2e)
263 if (wc>0x10c5 && wc != 0x10c7 && wc != 0x10cd) return wc;
264 else return wc + 0x2d00 - 0x10a0;
265 if (!lower && (unsigned)wc - 0x2d00 < 0x26)
266 if (wc>0x2d25 && wc != 0x2d27 && wc != 0x2d2d) return wc;
267 else return wc + 0x10a0 - 0x2d00;
268 if (lower && (unsigned)wc - 0x13a0 < 0x50)
269 return wc + 0xab70 - 0x13a0;
270 if (!lower && (unsigned)wc - 0xab70 < 0x50)
271 return wc + 0x13a0 - 0xab70;
272 for (i=0; casemaps[i].len; i++) {
273 int base = casemaps[i].upper + (lmask & casemaps[i].lower);
274 if ((unsigned)wc-base < casemaps[i].len) {
275 if (casemaps[i].lower == 1)
276 return wc + lower - ((wc-casemaps[i].upper)&1);
277 return wc + lmul*casemaps[i].lower;
280 for (i=0; pairs[i][1-lower]; i++) {
281 if (pairs[i][1-lower] == wc)
282 return pairs[i][lower];
284 if ((unsigned)wc - (0x10428 - 0x28*lower) < 0x28)
285 return wc - 0x28 + 0x50*lower;
286 if ((unsigned)wc - (0x104d8 - 0x28*lower) < 0x24)
287 return wc - 0x28 + 0x50*lower;
288 if ((unsigned)wc - (0x10cc0 - 0x40*lower) < 0x33)
289 return wc - 0x40 + 0x80*lower;
290 if ((unsigned)wc - (0x118c0 - 0x20*lower) < 0x20)
291 return wc - 0x20 + 0x40*lower;
292 if ((unsigned)wc - (0x1e922 - 0x22*lower) < 0x22)
293 return wc - 0x22 + 0x44*lower;
297 wint_t towupper(wint_t wc)
299 return (unsigned)wc < 128 ? toupper(wc) : __towcase(wc, 0);
302 wint_t towlower(wint_t wc)
304 return (unsigned)wc < 128 ? tolower(wc) : __towcase(wc, 1);
307 wint_t __towupper_l(wint_t c, locale_t l)
312 wint_t __towlower_l(wint_t c, locale_t l)
317 weak_alias(__towupper_l, towupper_l);
318 weak_alias(__towlower_l, towlower_l);