Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: fusl/src/ctype/towctrans.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <wctype.h> 1 #include <wctype.h>
2 #include "libc.h" 2 #include "libc.h"
3 3
4 #define CASEMAP(u1,u2,l) { (u1), (l)-(u1), (u2)-(u1)+1 } 4 #define CASEMAP(u1, u2, l) \
5 #define CASELACE(u1,u2) CASEMAP((u1),(u2),(u1)+1) 5 { (u1), (l) - (u1), (u2) - (u1) + 1 }
6 #define CASELACE(u1, u2) CASEMAP((u1), (u2), (u1) + 1)
6 7
7 static const struct { 8 static const struct {
8 » unsigned short upper; 9 unsigned short upper;
9 » signed char lower; 10 signed char lower;
10 » unsigned char len; 11 unsigned char len;
11 } casemaps[] = { 12 } casemaps[] = {
12 CASEMAP('A','Z','a'), 13 CASEMAP('A', 'Z', 'a'), CASEMAP(0xc0, 0xde, 0xe0),
13 CASEMAP(0xc0,0xde,0xe0), 14
14 15 CASELACE(0x0100, 0x012e), CASELACE(0x0132, 0x0136),
15 CASELACE(0x0100,0x012e), 16 CASELACE(0x0139, 0x0147), CASELACE(0x014a, 0x0176),
16 CASELACE(0x0132,0x0136), 17 CASELACE(0x0179, 0x017d),
17 CASELACE(0x0139,0x0147), 18
18 CASELACE(0x014a,0x0176), 19 CASELACE(0x370, 0x372), CASEMAP(0x391, 0x3a1, 0x3b1),
19 CASELACE(0x0179,0x017d), 20 CASEMAP(0x3a3, 0x3ab, 0x3c3), CASEMAP(0x400, 0x40f, 0x450),
20 21 CASEMAP(0x410, 0x42f, 0x430),
21 CASELACE(0x370,0x372), 22
22 CASEMAP(0x391,0x3a1,0x3b1), 23 CASELACE(0x460, 0x480), CASELACE(0x48a, 0x4be),
23 CASEMAP(0x3a3,0x3ab,0x3c3), 24 CASELACE(0x4c1, 0x4cd), CASELACE(0x4d0, 0x50e),
24 CASEMAP(0x400,0x40f,0x450), 25
25 CASEMAP(0x410,0x42f,0x430), 26 CASELACE(0x514, 0x526), CASEMAP(0x531, 0x556, 0x561),
26 27
27 CASELACE(0x460,0x480), 28 CASELACE(0x01a0, 0x01a4), CASELACE(0x01b3, 0x01b5),
28 CASELACE(0x48a,0x4be), 29 CASELACE(0x01cd, 0x01db), CASELACE(0x01de, 0x01ee),
29 CASELACE(0x4c1,0x4cd), 30 CASELACE(0x01f8, 0x021e), CASELACE(0x0222, 0x0232),
30 CASELACE(0x4d0,0x50e), 31 CASELACE(0x03d8, 0x03ee),
31 32
32 CASELACE(0x514,0x526), 33 CASELACE(0x1e00, 0x1e94), CASELACE(0x1ea0, 0x1efe),
33 CASEMAP(0x531,0x556,0x561), 34
34 35 CASEMAP(0x1f08, 0x1f0f, 0x1f00), CASEMAP(0x1f18, 0x1f1d, 0x1f10),
35 CASELACE(0x01a0,0x01a4), 36 CASEMAP(0x1f28, 0x1f2f, 0x1f20), CASEMAP(0x1f38, 0x1f3f, 0x1f30),
36 CASELACE(0x01b3,0x01b5), 37 CASEMAP(0x1f48, 0x1f4d, 0x1f40),
37 CASELACE(0x01cd,0x01db), 38
38 CASELACE(0x01de,0x01ee), 39 CASEMAP(0x1f68, 0x1f6f, 0x1f60), CASEMAP(0x1f88, 0x1f8f, 0x1f80),
39 CASELACE(0x01f8,0x021e), 40 CASEMAP(0x1f98, 0x1f9f, 0x1f90), CASEMAP(0x1fa8, 0x1faf, 0x1fa0),
40 CASELACE(0x0222,0x0232), 41 CASEMAP(0x1fb8, 0x1fb9, 0x1fb0), CASEMAP(0x1fba, 0x1fbb, 0x1f70),
41 CASELACE(0x03d8,0x03ee), 42 CASEMAP(0x1fc8, 0x1fcb, 0x1f72), CASEMAP(0x1fd8, 0x1fd9, 0x1fd0),
42 43 CASEMAP(0x1fda, 0x1fdb, 0x1f76), CASEMAP(0x1fe8, 0x1fe9, 0x1fe0),
43 CASELACE(0x1e00,0x1e94), 44 CASEMAP(0x1fea, 0x1feb, 0x1f7a), CASEMAP(0x1ff8, 0x1ff9, 0x1f78),
44 CASELACE(0x1ea0,0x1efe), 45 CASEMAP(0x1ffa, 0x1ffb, 0x1f7c),
45 46
46 CASEMAP(0x1f08,0x1f0f,0x1f00), 47 CASELACE(0x246, 0x24e), CASELACE(0x510, 0x512),
47 CASEMAP(0x1f18,0x1f1d,0x1f10), 48 CASEMAP(0x2160, 0x216f, 0x2170), CASEMAP(0x2c00, 0x2c2e, 0x2c30),
48 CASEMAP(0x1f28,0x1f2f,0x1f20), 49 CASELACE(0x2c67, 0x2c6b), CASELACE(0x2c80, 0x2ce2),
49 CASEMAP(0x1f38,0x1f3f,0x1f30), 50 CASELACE(0x2ceb, 0x2ced),
50 CASEMAP(0x1f48,0x1f4d,0x1f40), 51
51 52 CASELACE(0xa640, 0xa66c), CASELACE(0xa680, 0xa696),
52 CASEMAP(0x1f68,0x1f6f,0x1f60), 53
53 CASEMAP(0x1f88,0x1f8f,0x1f80), 54 CASELACE(0xa722, 0xa72e), CASELACE(0xa732, 0xa76e),
54 CASEMAP(0x1f98,0x1f9f,0x1f90), 55 CASELACE(0xa779, 0xa77b), CASELACE(0xa77e, 0xa786),
55 CASEMAP(0x1fa8,0x1faf,0x1fa0), 56
56 CASEMAP(0x1fb8,0x1fb9,0x1fb0), 57 CASELACE(0xa790, 0xa792), CASELACE(0xa7a0, 0xa7a8),
57 CASEMAP(0x1fba,0x1fbb,0x1f70), 58
58 CASEMAP(0x1fc8,0x1fcb,0x1f72), 59 CASEMAP(0xff21, 0xff3a, 0xff41), {0, 0, 0}};
59 CASEMAP(0x1fd8,0x1fd9,0x1fd0), 60
60 CASEMAP(0x1fda,0x1fdb,0x1f76), 61 static const unsigned short pairs[][2] = {{'I', 0x0131},
61 CASEMAP(0x1fe8,0x1fe9,0x1fe0), 62 {'S', 0x017f},
62 CASEMAP(0x1fea,0x1feb,0x1f7a), 63 {0x0130, 'i'},
63 CASEMAP(0x1ff8,0x1ff9,0x1f78), 64 {0x0178, 0x00ff},
64 CASEMAP(0x1ffa,0x1ffb,0x1f7c), 65 {0x0181, 0x0253},
65 66 {0x0182, 0x0183},
66 CASELACE(0x246,0x24e), 67 {0x0184, 0x0185},
67 CASELACE(0x510,0x512), 68 {0x0186, 0x0254},
68 CASEMAP(0x2160,0x216f,0x2170), 69 {0x0187, 0x0188},
69 CASEMAP(0x2c00,0x2c2e,0x2c30), 70 {0x0189, 0x0256},
70 CASELACE(0x2c67,0x2c6b), 71 {0x018a, 0x0257},
71 CASELACE(0x2c80,0x2ce2), 72 {0x018b, 0x018c},
72 CASELACE(0x2ceb,0x2ced), 73 {0x018e, 0x01dd},
73 74 {0x018f, 0x0259},
74 CASELACE(0xa640,0xa66c), 75 {0x0190, 0x025b},
75 CASELACE(0xa680,0xa696), 76 {0x0191, 0x0192},
76 77 {0x0193, 0x0260},
77 CASELACE(0xa722,0xa72e), 78 {0x0194, 0x0263},
78 CASELACE(0xa732,0xa76e), 79 {0x0196, 0x0269},
79 CASELACE(0xa779,0xa77b), 80 {0x0197, 0x0268},
80 CASELACE(0xa77e,0xa786), 81 {0x0198, 0x0199},
81 82 {0x019c, 0x026f},
82 CASELACE(0xa790,0xa792), 83 {0x019d, 0x0272},
83 CASELACE(0xa7a0,0xa7a8), 84 {0x019f, 0x0275},
84 85 {0x01a6, 0x0280},
85 CASEMAP(0xff21,0xff3a,0xff41), 86 {0x01a7, 0x01a8},
86 { 0,0,0 } 87 {0x01a9, 0x0283},
87 }; 88 {0x01ac, 0x01ad},
88 89 {0x01ae, 0x0288},
89 static const unsigned short pairs[][2] = { 90 {0x01af, 0x01b0},
90 { 'I', 0x0131 }, 91 {0x01b1, 0x028a},
91 { 'S', 0x017f }, 92 {0x01b2, 0x028b},
92 { 0x0130, 'i' }, 93 {0x01b7, 0x0292},
93 { 0x0178, 0x00ff }, 94 {0x01b8, 0x01b9},
94 { 0x0181, 0x0253 }, 95 {0x01bc, 0x01bd},
95 { 0x0182, 0x0183 }, 96 {0x01c4, 0x01c6},
96 { 0x0184, 0x0185 }, 97 {0x01c4, 0x01c5},
97 { 0x0186, 0x0254 }, 98 {0x01c5, 0x01c6},
98 { 0x0187, 0x0188 }, 99 {0x01c7, 0x01c9},
99 { 0x0189, 0x0256 }, 100 {0x01c7, 0x01c8},
100 { 0x018a, 0x0257 }, 101 {0x01c8, 0x01c9},
101 { 0x018b, 0x018c }, 102 {0x01ca, 0x01cc},
102 { 0x018e, 0x01dd }, 103 {0x01ca, 0x01cb},
103 { 0x018f, 0x0259 }, 104 {0x01cb, 0x01cc},
104 { 0x0190, 0x025b }, 105 {0x01f1, 0x01f3},
105 { 0x0191, 0x0192 }, 106 {0x01f1, 0x01f2},
106 { 0x0193, 0x0260 }, 107 {0x01f2, 0x01f3},
107 { 0x0194, 0x0263 }, 108 {0x01f4, 0x01f5},
108 { 0x0196, 0x0269 }, 109 {0x01f6, 0x0195},
109 { 0x0197, 0x0268 }, 110 {0x01f7, 0x01bf},
110 { 0x0198, 0x0199 }, 111 {0x0220, 0x019e},
111 { 0x019c, 0x026f }, 112 {0x0386, 0x03ac},
112 { 0x019d, 0x0272 }, 113 {0x0388, 0x03ad},
113 { 0x019f, 0x0275 }, 114 {0x0389, 0x03ae},
114 { 0x01a6, 0x0280 }, 115 {0x038a, 0x03af},
115 { 0x01a7, 0x01a8 }, 116 {0x038c, 0x03cc},
116 { 0x01a9, 0x0283 }, 117 {0x038e, 0x03cd},
117 { 0x01ac, 0x01ad }, 118 {0x038f, 0x03ce},
118 { 0x01ae, 0x0288 }, 119 {0x0399, 0x0345},
119 { 0x01af, 0x01b0 }, 120 {0x0399, 0x1fbe},
120 { 0x01b1, 0x028a }, 121 {0x03a3, 0x03c2},
121 { 0x01b2, 0x028b }, 122 {0x03f7, 0x03f8},
122 { 0x01b7, 0x0292 }, 123 {0x03fa, 0x03fb},
123 { 0x01b8, 0x01b9 }, 124 {0x1e60, 0x1e9b},
124 { 0x01bc, 0x01bd }, 125 {0x1e9e, 0xdf},
125 { 0x01c4, 0x01c6 }, 126
126 { 0x01c4, 0x01c5 }, 127 {0x1f59, 0x1f51},
127 { 0x01c5, 0x01c6 }, 128 {0x1f5b, 0x1f53},
128 { 0x01c7, 0x01c9 }, 129 {0x1f5d, 0x1f55},
129 { 0x01c7, 0x01c8 }, 130 {0x1f5f, 0x1f57},
130 { 0x01c8, 0x01c9 }, 131 {0x1fbc, 0x1fb3},
131 { 0x01ca, 0x01cc }, 132 {0x1fcc, 0x1fc3},
132 { 0x01ca, 0x01cb }, 133 {0x1fec, 0x1fe5},
133 { 0x01cb, 0x01cc }, 134 {0x1ffc, 0x1ff3},
134 { 0x01f1, 0x01f3 }, 135
135 { 0x01f1, 0x01f2 }, 136 {0x23a, 0x2c65},
136 { 0x01f2, 0x01f3 }, 137 {0x23b, 0x23c},
137 { 0x01f4, 0x01f5 }, 138 {0x23d, 0x19a},
138 { 0x01f6, 0x0195 }, 139 {0x23e, 0x2c66},
139 { 0x01f7, 0x01bf }, 140 {0x241, 0x242},
140 { 0x0220, 0x019e }, 141 {0x243, 0x180},
141 { 0x0386, 0x03ac }, 142 {0x244, 0x289},
142 { 0x0388, 0x03ad }, 143 {0x245, 0x28c},
143 { 0x0389, 0x03ae }, 144 {0x3f4, 0x3b8},
144 { 0x038a, 0x03af }, 145 {0x3f9, 0x3f2},
145 { 0x038c, 0x03cc }, 146 {0x3fd, 0x37b},
146 { 0x038e, 0x03cd }, 147 {0x3fe, 0x37c},
147 { 0x038f, 0x03ce }, 148 {0x3ff, 0x37d},
148 { 0x0399, 0x0345 }, 149 {0x4c0, 0x4cf},
149 { 0x0399, 0x1fbe }, 150
150 { 0x03a3, 0x03c2 }, 151 {0x2126, 0x3c9},
151 { 0x03f7, 0x03f8 }, 152 {0x212a, 'k'},
152 { 0x03fa, 0x03fb }, 153 {0x212b, 0xe5},
153 { 0x1e60, 0x1e9b }, 154 {0x2132, 0x214e},
154 { 0x1e9e, 0xdf }, 155 {0x2183, 0x2184},
155 156 {0x2c60, 0x2c61},
156 { 0x1f59, 0x1f51 }, 157 {0x2c62, 0x26b},
157 { 0x1f5b, 0x1f53 }, 158 {0x2c63, 0x1d7d},
158 { 0x1f5d, 0x1f55 }, 159 {0x2c64, 0x27d},
159 { 0x1f5f, 0x1f57 }, 160 {0x2c6d, 0x251},
160 { 0x1fbc, 0x1fb3 }, 161 {0x2c6e, 0x271},
161 { 0x1fcc, 0x1fc3 }, 162 {0x2c6f, 0x250},
162 { 0x1fec, 0x1fe5 }, 163 {0x2c70, 0x252},
163 { 0x1ffc, 0x1ff3 }, 164 {0x2c72, 0x2c73},
164 165 {0x2c75, 0x2c76},
165 { 0x23a, 0x2c65 }, 166 {0x2c7e, 0x23f},
166 { 0x23b, 0x23c }, 167 {0x2c7f, 0x240},
167 { 0x23d, 0x19a }, 168 {0x2cf2, 0x2cf3},
168 { 0x23e, 0x2c66 }, 169
169 { 0x241, 0x242 }, 170 {0xa77d, 0x1d79},
170 { 0x243, 0x180 }, 171 {0xa78b, 0xa78c},
171 { 0x244, 0x289 }, 172 {0xa78d, 0x265},
172 { 0x245, 0x28c }, 173 {0xa7aa, 0x266},
173 { 0x3f4, 0x3b8 }, 174
174 { 0x3f9, 0x3f2 }, 175 {0x10c7, 0x2d27},
175 { 0x3fd, 0x37b }, 176 {0x10cd, 0x2d2d},
176 { 0x3fe, 0x37c }, 177
177 { 0x3ff, 0x37d }, 178 /* bogus greek 'symbol' letters */
178 { 0x4c0, 0x4cf }, 179 {0x376, 0x377},
179 180 {0x39c, 0xb5},
180 { 0x2126, 0x3c9 }, 181 {0x392, 0x3d0},
181 { 0x212a, 'k' }, 182 {0x398, 0x3d1},
182 { 0x212b, 0xe5 }, 183 {0x3a6, 0x3d5},
183 { 0x2132, 0x214e }, 184 {0x3a0, 0x3d6},
184 { 0x2183, 0x2184 }, 185 {0x39a, 0x3f0},
185 { 0x2c60, 0x2c61 }, 186 {0x3a1, 0x3f1},
186 { 0x2c62, 0x26b }, 187 {0x395, 0x3f5},
187 { 0x2c63, 0x1d7d }, 188 {0x3cf, 0x3d7},
188 { 0x2c64, 0x27d }, 189
189 { 0x2c6d, 0x251 }, 190 {0, 0}};
190 { 0x2c6e, 0x271 }, 191
191 { 0x2c6f, 0x250 }, 192 static wchar_t __towcase(wchar_t wc, int lower) {
192 { 0x2c70, 0x252 }, 193 int i;
193 { 0x2c72, 0x2c73 }, 194 int lmul = 2 * lower - 1;
194 { 0x2c75, 0x2c76 }, 195 int lmask = lower - 1;
195 { 0x2c7e, 0x23f }, 196 /* no letters with case in these large ranges */
196 { 0x2c7f, 0x240 }, 197 if (!iswalpha(wc) || (unsigned)wc - 0x0600 <= 0x0fff - 0x0600 ||
197 { 0x2cf2, 0x2cf3 }, 198 (unsigned)wc - 0x2e00 <= 0xa63f - 0x2e00 ||
198 199 (unsigned)wc - 0xa800 <= 0xfeff - 0xa800)
199 { 0xa77d, 0x1d79 }, 200 return wc;
200 { 0xa78b, 0xa78c }, 201 /* special case because the diff between upper/lower is too big */
201 { 0xa78d, 0x265 }, 202 if (lower && (unsigned)wc - 0x10a0 < 0x2e) {
202 { 0xa7aa, 0x266 }, 203 if (wc > 0x10c5 && wc != 0x10c7 && wc != 0x10cd)
203 204 return wc;
204 { 0x10c7, 0x2d27 }, 205 else
205 { 0x10cd, 0x2d2d }, 206 return wc + 0x2d00 - 0x10a0;
206 207 }
207 /* bogus greek 'symbol' letters */ 208 if (!lower && (unsigned)wc - 0x2d00 < 0x26) {
208 { 0x376, 0x377 }, 209 if (wc > 0x2d25 && wc != 0x2d27 && wc != 0x2d2d)
209 { 0x39c, 0xb5 }, 210 return wc;
210 { 0x392, 0x3d0 }, 211 else
211 { 0x398, 0x3d1 }, 212 return wc + 0x10a0 - 0x2d00;
212 { 0x3a6, 0x3d5 }, 213 }
213 { 0x3a0, 0x3d6 }, 214 for (i = 0; casemaps[i].len; i++) {
214 { 0x39a, 0x3f0 }, 215 int base = casemaps[i].upper + (lmask & casemaps[i].lower);
215 { 0x3a1, 0x3f1 }, 216 if ((unsigned)wc - base < casemaps[i].len) {
216 { 0x395, 0x3f5 }, 217 if (casemaps[i].lower == 1)
217 { 0x3cf, 0x3d7 }, 218 return wc + lower - ((wc - casemaps[i].upper) & 1);
218 219 return wc + lmul * casemaps[i].lower;
219 { 0,0 } 220 }
220 }; 221 }
221 222 for (i = 0; pairs[i][1 - lower]; i++) {
222 223 if (pairs[i][1 - lower] == wc)
223 static wchar_t __towcase(wchar_t wc, int lower) 224 return pairs[i][lower];
224 { 225 }
225 int i; 226 if ((unsigned)wc - (0x10428 - 0x28 * lower) < 0x28)
226 int lmul = 2*lower-1; 227 return wc - 0x28 + 0x50 * lower;
227 int lmask = lower-1; 228 return wc;
228 /* no letters with case in these large ranges */ 229 }
229 if (!iswalpha(wc) 230
230 || (unsigned)wc - 0x0600 <= 0x0fff-0x0600 231 wint_t towupper(wint_t wc) {
231 || (unsigned)wc - 0x2e00 <= 0xa63f-0x2e00 232 return __towcase(wc, 0);
232 || (unsigned)wc - 0xa800 <= 0xfeff-0xa800) 233 }
233 return wc; 234
234 /* special case because the diff between upper/lower is too big */ 235 wint_t towlower(wint_t wc) {
235 if (lower && (unsigned)wc - 0x10a0 < 0x2e) { 236 return __towcase(wc, 1);
236 if (wc>0x10c5 && wc != 0x10c7 && wc != 0x10cd) return wc; 237 }
237 else return wc + 0x2d00 - 0x10a0; 238
238 } 239 wint_t __towupper_l(wint_t c, locale_t l) {
239 if (!lower && (unsigned)wc - 0x2d00 < 0x26) { 240 return towupper(c);
240 if (wc>0x2d25 && wc != 0x2d27 && wc != 0x2d2d) return wc; 241 }
241 else return wc + 0x10a0 - 0x2d00; 242
242 } 243 wint_t __towlower_l(wint_t c, locale_t l) {
243 for (i=0; casemaps[i].len; i++) { 244 return towlower(c);
244 int base = casemaps[i].upper + (lmask & casemaps[i].lower);
245 if ((unsigned)wc-base < casemaps[i].len) {
246 if (casemaps[i].lower == 1)
247 return wc + lower - ((wc-casemaps[i].upper)&1);
248 return wc + lmul*casemaps[i].lower;
249 }
250 }
251 for (i=0; pairs[i][1-lower]; i++) {
252 if (pairs[i][1-lower] == wc)
253 return pairs[i][lower];
254 }
255 if ((unsigned)wc - (0x10428 - 0x28*lower) < 0x28)
256 return wc - 0x28 + 0x50*lower;
257 return wc;
258 }
259
260 wint_t towupper(wint_t wc)
261 {
262 return __towcase(wc, 0);
263 }
264
265 wint_t towlower(wint_t wc)
266 {
267 return __towcase(wc, 1);
268 }
269
270 wint_t __towupper_l(wint_t c, locale_t l)
271 {
272 return towupper(c);
273 }
274
275 wint_t __towlower_l(wint_t c, locale_t l)
276 {
277 return towlower(c);
278 } 245 }
279 246
280 weak_alias(__towupper_l, towupper_l); 247 weak_alias(__towupper_l, towupper_l);
281 weak_alias(__towlower_l, towlower_l); 248 weak_alias(__towlower_l, towlower_l);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698