Debian Codegraph @

src/com/google/javascript/jscomp/regex/CaseCanonicalize.java

raw symbols SCIP
1 /*
2 * Copyright 2011 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp.regex;
18
19 import com.google.common.collect.ImmutableList;
20
21 /**
22 * Implements the ECMAScript 5
23 * <a href="http://es5.github.com/#Canonicalize">Canonicalize</a> operation
24 * used to specify how case-insensitive regular expressions match.
25 *
26 * <p>
27 * From section <a href="http://es5.github.com/#x15.10.2.9">15.10.2.9</a>,
28 * <blockquote>
29 * The abstract operation Canonicalize takes a character parameter ch and
30 * performs the following steps:
31 * <ul>
32 * <li>If IgnoreCase is false, return ch.
33 * <li>Let u be ch converted to upper case as if by calling the standard
34 * built-in method {@code String.prototype.toUpperCase} on the one-character
35 * String ch.
36 * <li>If u does not consist of a single character, return ch.
37 * <li>Let cu be u's character.
38 * <li>If ch's code unit value is greater than or equal to decimal 128 and
39 * cu's code unit value is less than decimal 128, then return ch.
40 * <li>Return cu.
41 * </ul>
42 *
43 * @author Mike Samuel <[email protected]>
44 */
45 public final class CaseCanonicalize {
46
47 private CaseCanonicalize() {
48 // Uninstantiable.
49 }
50
51 // Below are tables that implement the Canonicalize operation.
52 // We cannot use java.lang.Character.toUpperCase since that is based on
53 // a more modern version of Unicode than that required by the ECMAScript spec.
54
55 /**
56 * Set of code units that are case-insensitively equivalent to some other
57 * code unit according to the EcmaScript
58 * <a href="http://es5.github.com/#Canonicalize">Canonicalize</a> operation
59 * described in section 15.10.2.8.
60 * The case sensitive characters are the ones that canonicalize to a character
61 * other than themselves or have a character that canonicalizes to them.
62 * Canonicalize is based on the definition of
63 * {@code String.prototype.toUpperCase} which is itself based on Unicode 3.0.0
64 * as specified at
65 * <a href="ftp://ftp.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.txt">
66 * UnicodeData-3.0.0
67 * </a>
68 * and <a href="ftp://ftp.unicode.org/Public/3.0-Update/SpecialCasing-2.txt">
69 * SpecialCasings-2.txt
70 * </a>.
71 *
72 * <p>
73 * This table was generated by running the below on Chrome:
74 * </p>
75 * <pre>
76 * for (var cc = 0; cc < 0x10000; ++cc) {
77 * var ch = String.fromCharCode(cc);
78 * var u = ch.toUpperCase();
79 * if (ch != u && u.length === 1) {
80 * var cu = u.charCodeAt(0);
81 * if (cc <= 128 || u.charCodeAt(0) > 128) {
82 * print('0x' + cc.toString(16) + ', 0x' + cu.toString(16) + ',');
83 * }
84 * }
85 * }
86 * </pre>
87 */
88 public static final CharRanges CASE_SENSITIVE = CharRanges.withRanges(
89 0x41, 0x5b,
90 0x61, 0x7b,
91 0xb5, 0xb6,
92 0xc0, 0xd7,
93 0xd8, 0xdf,
94 0xe0, 0xf7,
95 0xf8, 0x130,
96 0x132, 0x138,
97 0x139, 0x149,
98 0x14a, 0x17f,
99 0x180, 0x18d,
100 0x18e, 0x19b,
101 0x19c, 0x1aa,
102 0x1ac, 0x1ba,
103 0x1bc, 0x1be,
104 0x1bf, 0x1c0,
105 0x1c4, 0x1f0,
106 0x1f1, 0x221,
107 0x222, 0x234,
108 0x23a, 0x23f,
109 0x241, 0x250,
110 0x253, 0x255,
111 0x256, 0x258,
112 0x259, 0x25a,
113 0x25b, 0x25c,
114 0x260, 0x261,
115 0x263, 0x264,
116 0x268, 0x26a,
117 0x26b, 0x26c,
118 0x26f, 0x270,
119 0x272, 0x273,
120 0x275, 0x276,
121 0x27d, 0x27e,
122 0x280, 0x281,
123 0x283, 0x284,
124 0x288, 0x28d,
125 0x292, 0x293,
126 0x345, 0x346,
127 0x37b, 0x37e,
128 0x386, 0x387,
129 0x388, 0x38b,
130 0x38c, 0x38d,
131 0x38e, 0x390,
132 0x391, 0x3a2,
133 0x3a3, 0x3b0,
134 0x3b1, 0x3cf,
135 0x3d0, 0x3d2,
136 0x3d5, 0x3d7,
137 0x3d8, 0x3f3,
138 0x3f5, 0x3f6,
139 0x3f7, 0x3fc,
140 0x3fd, 0x482,
141 0x48a, 0x514,
142 0x531, 0x557,
143 0x561, 0x587,
144 0x10a0, 0x10c6,
145 0x1d7d, 0x1d7e,
146 0x1e00, 0x1e96,
147 0x1e9b, 0x1e9c,
148 0x1ea0, 0x1efa,
149 0x1f00, 0x1f16,
150 0x1f18, 0x1f1e,
151 0x1f20, 0x1f46,
152 0x1f48, 0x1f4e,
153 0x1f51, 0x1f52,
154 0x1f53, 0x1f54,
155 0x1f55, 0x1f56,
156 0x1f57, 0x1f58,
157 0x1f59, 0x1f5a,
158 0x1f5b, 0x1f5c,
159 0x1f5d, 0x1f5e,
160 0x1f5f, 0x1f7e,
161 0x1fb0, 0x1fb2,
162 0x1fb8, 0x1fbc,
163 0x1fbe, 0x1fbf,
164 0x1fc8, 0x1fcc,
165 0x1fd0, 0x1fd2,
166 0x1fd8, 0x1fdc,
167 0x1fe0, 0x1fe2,
168 0x1fe5, 0x1fe6,
169 0x1fe8, 0x1fed,
170 0x1ff8, 0x1ffc,
171 0x2132, 0x2133,
172 0x214e, 0x214f,
173 0x2160, 0x2180,
174 0x2183, 0x2185,
175 0x24b6, 0x24ea,
176 0x2c00, 0x2c2f,
177 0x2c30, 0x2c5f,
178 0x2c60, 0x2c6d,
179 0x2c75, 0x2c77,
180 0x2c80, 0x2ce4,
181 0x2d00, 0x2d26,
182 0xff21, 0xff3b,
183 0xff41, 0xff5b
184 );
185
186
187 /**
188 * Returns the case canonical version of the given string.
189 */
190 public static String caseCanonicalize(String s) {
191 for (int i = 0, n = s.length(); i < n; ++i) {
192 char ch = s.charAt(i);
193 char cu = caseCanonicalize(ch);
194 if (cu != ch) {
195 StringBuilder sb = new StringBuilder(s);
196 sb.setCharAt(i, cu);
197 while (++i < n) {
198 sb.setCharAt(i, caseCanonicalize(s.charAt(i)));
199 }
200 return sb.toString();
201 }
202 }
203 return s;
204 }
205
206 /**
207 * Returns the case canonical version of the given code-unit. ECMAScript 5
208 * explicitly says that code-units are to be treated as their code-point
209 * equivalent, even surrogates.
210 */
211 public static char caseCanonicalize(char ch) {
212 if (ch < 0x80) { // Normal case.
213 return ('A' <= ch && ch <= 'Z') ? (char) (ch | 32) : ch;
214 }
215 // Non-ASCII case.
216 if (CASE_SENSITIVE.contains(ch)) {
217 for (DeltaSet ds : CANON_DELTA_SETS) {
218 if (ds.codeUnits.contains(ch)) {
219 return (char) (ch - ds.delta);
220 }
221 }
222 }
223 return ch;
224 }
225
226 /**
227 * Given a character range that may include case sensitive code-units,
228 * such as {@code [0-9B-M]}, returns the character range that includes all
229 * the code-units in the input and those that are case-insensitively
230 * equivalent to a code-unit in the input.
231 */
232 public static CharRanges expandToAllMatched(CharRanges ranges) {
233 CharRanges caseSensitive = ranges.intersection(CASE_SENSITIVE);
234 if (caseSensitive.isEmpty()) { return ranges; }
235 CharRanges expanded = CharRanges.EMPTY;
236 for (DeltaSet ds : DELTA_SETS) {
237 expanded = expanded.union(
238 caseSensitive.intersection(ds.codeUnits).shift(-ds.delta));
239 }
240 return ranges.union(expanded);
241 }
242
243
244 private static final CharRanges UCASE_ASCII_LETTERS
245 = CharRanges.inclusive('A', 'Z');
246
247 /**
248 * Given a character range that may include case sensitive code-units,
249 * such as {@code [0-9B-M]}, returns the character range that includes
250 * the minimal set of code units such that for every code unit in the
251 * input there is a case-sensitively equivalent canonical code unit in the
252 * output.
253 */
254 public static CharRanges reduceToMinimum(CharRanges ranges) {
255 CharRanges caseSensitive = ranges.intersection(CASE_SENSITIVE);
256 if (caseSensitive.isEmpty()) { return ranges; }
257 CharRanges expanded = CharRanges.EMPTY;
258 for (DeltaSet ds : CANON_DELTA_SETS) {
259 expanded = expanded.union(
260 caseSensitive.intersection(ds.codeUnits).shift(-ds.delta));
261 }
262 // Letters a-z gzip better than uppercase A-Z since JavaScript keywords
263 // are lower-case, so, even though the definition of Canonicalize is
264 // based on String.prototype.toUpperCase, we use lowercase ASCII characters
265 // in the minimal form.
266 expanded = expanded.difference(UCASE_ASCII_LETTERS).union(
267 expanded.intersection(UCASE_ASCII_LETTERS).shift(32));
268 return ranges.difference(caseSensitive).union(expanded);
269 }
270
271 /**
272 * Sets of code units broken down by delta that are case-insensitively
273 * equivalent to another code unit that differs from the first by that delta.
274 */
275 private static final ImmutableList<DeltaSet> DELTA_SETS = ImmutableList.of(
276 new DeltaSet(-10795, CharRanges.withMembers(0x23a)),
277 new DeltaSet(-10792, CharRanges.withMembers(0x23e)),
278 new DeltaSet(-10743, CharRanges.withMembers(0x26b)),
279 new DeltaSet(-10727, CharRanges.withMembers(0x27d)),
280 new DeltaSet(-7264, CharRanges.withRanges(0x10a0, 0x10c6)),
281 new DeltaSet(-7205, CharRanges.withMembers(0x399)),
282 new DeltaSet(-3814, CharRanges.withMembers(0x1d7d)),
283 new DeltaSet(-743, CharRanges.withMembers(0xb5)),
284 new DeltaSet(-219, CharRanges.withMembers(0x1b7)),
285 new DeltaSet(-218, CharRanges.withMembers(0x1a6, 0x1a9, 0x1ae)),
286 new DeltaSet(-217, CharRanges.withRanges(0x1b1, 0x1b3)),
287 new DeltaSet(-214, CharRanges.withMembers(0x19f)),
288 new DeltaSet(-213, CharRanges.withMembers(0x19d)),
289 new DeltaSet(-211, CharRanges.withMembers(0x196, 0x19c)),
290 new DeltaSet(-210, CharRanges.withMembers(0x181)),
291 new DeltaSet(-209, CharRanges.withMembers(0x197)),
292 new DeltaSet(-207, CharRanges.withMembers(0x194)),
293 new DeltaSet(-206, CharRanges.withMembers(0x186)),
294 new DeltaSet(-205, CharRanges.withRanges(0x189, 0x18b, 0x193, 0x194)),
295 new DeltaSet(-203, CharRanges.withMembers(0x190)),
296 new DeltaSet(-202, CharRanges.withMembers(0x18f)),
297 new DeltaSet(-195, CharRanges.withMembers(0x180)),
298 new DeltaSet(-163, CharRanges.withMembers(0x19a)),
299 new DeltaSet(-130, CharRanges.withRanges(0x19e, 0x19f, 0x37b, 0x37e)),
300 new DeltaSet(-128, CharRanges.withRanges(0x1f78, 0x1f7a)),
301 new DeltaSet(-126, CharRanges.withRanges(0x1f7c, 0x1f7e)),
302 new DeltaSet(-121, CharRanges.withMembers(0xff)),
303 new DeltaSet(-112, CharRanges.withRanges(0x1f7a, 0x1f7c)),
304 new DeltaSet(-100, CharRanges.withRanges(0x1f76, 0x1f78)),
305 new DeltaSet(-97, CharRanges.withMembers(0x195)),
306 new DeltaSet(-96, CharRanges.withMembers(0x395)),
307 new DeltaSet(-86, CharRanges.withRanges(0x39a, 0x39b, 0x1f72, 0x1f76)),
308 new DeltaSet(-84, CharRanges.withMembers(0x345)),
309 new DeltaSet(-80, CharRanges.withRanges(0x3a1, 0x3a2, 0x400, 0x410)),
310 new DeltaSet(-79, CharRanges.withMembers(0x18e)),
311 new DeltaSet(-74, CharRanges.withRanges(0x1f70, 0x1f72)),
312 new DeltaSet(-71, CharRanges.withMembers(0x245)),
313 new DeltaSet(-69, CharRanges.withMembers(0x244)),
314 new DeltaSet(-64, CharRanges.withMembers(0x38c)),
315 new DeltaSet(-63, CharRanges.withRanges(0x38e, 0x390)),
316 new DeltaSet(-62, CharRanges.withMembers(0x392)),
317 new DeltaSet(-59, CharRanges.withMembers(0x1e60)),
318 new DeltaSet(-57, CharRanges.withMembers(0x398)),
319 new DeltaSet(-56, CharRanges.withMembers(0x1bf)),
320 new DeltaSet(-54, CharRanges.withMembers(0x3a0)),
321 new DeltaSet(-48, CharRanges.withRanges(0x531, 0x557, 0x2c00, 0x2c2f)),
322 new DeltaSet(-47, CharRanges.withMembers(0x3a6)),
323 new DeltaSet(-38, CharRanges.withMembers(0x386)),
324 new DeltaSet(-37, CharRanges.withRanges(0x388, 0x38b)),
325 new DeltaSet(-32, CharRanges.withRanges(
326 0x41, 0x5b, 0xc0, 0xd7, 0xd8, 0xdf, 0x391, 0x3a2, 0x3a3, 0x3ac,
327 0x410, 0x430, 0xff21, 0xff3b)),
328 new DeltaSet(-31, CharRanges.withMembers(0x3a3)),
329 new DeltaSet(-28, CharRanges.withMembers(0x2132)),
330 new DeltaSet(-26, CharRanges.withRanges(0x24b6, 0x24d0)),
331 new DeltaSet(-16, CharRanges.withRanges(0x2160, 0x2170)),
332 new DeltaSet(-15, CharRanges.withMembers(0x4c0)),
333 new DeltaSet(-8, CharRanges.withRanges(
334 0x1f00, 0x1f08, 0x1f10, 0x1f16, 0x1f20, 0x1f28, 0x1f30, 0x1f38,
335 0x1f40, 0x1f46, 0x1f51, 0x1f52, 0x1f53, 0x1f54, 0x1f55, 0x1f56,
336 0x1f57, 0x1f58, 0x1f60, 0x1f68, 0x1fb0, 0x1fb2, 0x1fd0, 0x1fd2,
337 0x1fe0, 0x1fe2)),
338 new DeltaSet(-7, CharRanges.withMembers(0x3f2, 0x1fe5)),
339 new DeltaSet(-2, CharRanges.withMembers(0x1c4, 0x1c7, 0x1ca, 0x1f1)),
340 new DeltaSet(-1, CharRanges.withMembers(
341 0x100, 0x102, 0x104, 0x106, 0x108, 0x10a, 0x10c, 0x10e, 0x110, 0x112,
342 0x114, 0x116, 0x118, 0x11a, 0x11c, 0x11e, 0x120, 0x122, 0x124, 0x126,
343 0x128, 0x12a, 0x12c, 0x12e, 0x132, 0x134, 0x136, 0x139, 0x13b, 0x13d,
344 0x13f, 0x141, 0x143, 0x145, 0x147, 0x14a, 0x14c, 0x14e, 0x150, 0x152,
345 0x154, 0x156, 0x158, 0x15a, 0x15c, 0x15e, 0x160, 0x162, 0x164, 0x166,
346 0x168, 0x16a, 0x16c, 0x16e, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17b,
347 0x17d, 0x182, 0x184, 0x187, 0x18b, 0x191, 0x198, 0x1a0, 0x1a2, 0x1a4,
348 0x1a7, 0x1ac, 0x1af, 0x1b3, 0x1b5, 0x1b8, 0x1bc, 0x1c4, 0x1c7, 0x1ca,
349 0x1cd, 0x1cf, 0x1d1, 0x1d3, 0x1d5, 0x1d7, 0x1d9, 0x1db, 0x1de, 0x1e0,
350 0x1e2, 0x1e4, 0x1e6, 0x1e8, 0x1ea, 0x1ec, 0x1ee, 0x1f1, 0x1f4, 0x1f8,
351 0x1fa, 0x1fc, 0x1fe, 0x200, 0x202, 0x204, 0x206, 0x208, 0x20a, 0x20c,
352 0x20e, 0x210, 0x212, 0x214, 0x216, 0x218, 0x21a, 0x21c, 0x21e, 0x222,
353 0x224, 0x226, 0x228, 0x22a, 0x22c, 0x22e, 0x230, 0x232, 0x23b, 0x241,
354 0x246, 0x248, 0x24a, 0x24c, 0x24e, 0x3d8, 0x3da, 0x3dc, 0x3de, 0x3e0,
355 0x3e2, 0x3e4, 0x3e6, 0x3e8, 0x3ea, 0x3ec, 0x3ee, 0x3f7, 0x3fa, 0x460,
356 0x462, 0x464, 0x466, 0x468, 0x46a, 0x46c, 0x46e, 0x470, 0x472, 0x474,
357 0x476, 0x478, 0x47a, 0x47c, 0x47e, 0x480, 0x48a, 0x48c, 0x48e, 0x490,
358 0x492, 0x494, 0x496, 0x498, 0x49a, 0x49c, 0x49e, 0x4a0, 0x4a2, 0x4a4,
359 0x4a6, 0x4a8, 0x4aa, 0x4ac, 0x4ae, 0x4b0, 0x4b2, 0x4b4, 0x4b6, 0x4b8,
360 0x4ba, 0x4bc, 0x4be, 0x4c1, 0x4c3, 0x4c5, 0x4c7, 0x4c9, 0x4cb, 0x4cd,
361 0x4d0, 0x4d2, 0x4d4, 0x4d6, 0x4d8, 0x4da, 0x4dc, 0x4de, 0x4e0, 0x4e2,
362 0x4e4, 0x4e6, 0x4e8, 0x4ea, 0x4ec, 0x4ee, 0x4f0, 0x4f2, 0x4f4, 0x4f6,
363 0x4f8, 0x4fa, 0x4fc, 0x4fe, 0x500, 0x502, 0x504, 0x506, 0x508, 0x50a,
364 0x50c, 0x50e, 0x510, 0x512, 0x1e00, 0x1e02, 0x1e04, 0x1e06, 0x1e08,
365 0x1e0a, 0x1e0c, 0x1e0e, 0x1e10, 0x1e12, 0x1e14, 0x1e16, 0x1e18,
366 0x1e1a, 0x1e1c, 0x1e1e, 0x1e20, 0x1e22, 0x1e24, 0x1e26, 0x1e28,
367 0x1e2a, 0x1e2c, 0x1e2e, 0x1e30, 0x1e32, 0x1e34, 0x1e36, 0x1e38,
368 0x1e3a, 0x1e3c, 0x1e3e, 0x1e40, 0x1e42, 0x1e44, 0x1e46, 0x1e48,
369 0x1e4a, 0x1e4c, 0x1e4e, 0x1e50, 0x1e52, 0x1e54, 0x1e56, 0x1e58,
370 0x1e5a, 0x1e5c, 0x1e5e, 0x1e60, 0x1e62, 0x1e64, 0x1e66, 0x1e68,
371 0x1e6a, 0x1e6c, 0x1e6e, 0x1e70, 0x1e72, 0x1e74, 0x1e76, 0x1e78,
372 0x1e7a, 0x1e7c, 0x1e7e, 0x1e80, 0x1e82, 0x1e84, 0x1e86, 0x1e88,
373 0x1e8a, 0x1e8c, 0x1e8e, 0x1e90, 0x1e92, 0x1e94, 0x1ea0, 0x1ea2,
374 0x1ea4, 0x1ea6, 0x1ea8, 0x1eaa, 0x1eac, 0x1eae, 0x1eb0, 0x1eb2,
375 0x1eb4, 0x1eb6, 0x1eb8, 0x1eba, 0x1ebc, 0x1ebe, 0x1ec0, 0x1ec2,
376 0x1ec4, 0x1ec6, 0x1ec8, 0x1eca, 0x1ecc, 0x1ece, 0x1ed0, 0x1ed2,
377 0x1ed4, 0x1ed6, 0x1ed8, 0x1eda, 0x1edc, 0x1ede, 0x1ee0, 0x1ee2,
378 0x1ee4, 0x1ee6, 0x1ee8, 0x1eea, 0x1eec, 0x1eee, 0x1ef0, 0x1ef2,
379 0x1ef4, 0x1ef6, 0x1ef8, 0x2183, 0x2c60, 0x2c67, 0x2c69, 0x2c6b,
380 0x2c75, 0x2c80, 0x2c82, 0x2c84, 0x2c86, 0x2c88, 0x2c8a, 0x2c8c,
381 0x2c8e, 0x2c90, 0x2c92, 0x2c94, 0x2c96, 0x2c98, 0x2c9a, 0x2c9c,
382 0x2c9e, 0x2ca0, 0x2ca2, 0x2ca4, 0x2ca6, 0x2ca8, 0x2caa, 0x2cac,
383 0x2cae, 0x2cb0, 0x2cb2, 0x2cb4, 0x2cb6, 0x2cb8, 0x2cba, 0x2cbc,
384 0x2cbe, 0x2cc0, 0x2cc2, 0x2cc4, 0x2cc6, 0x2cc8, 0x2cca, 0x2ccc,
385 0x2cce, 0x2cd0, 0x2cd2, 0x2cd4, 0x2cd6, 0x2cd8, 0x2cda, 0x2cdc,
386 0x2cde, 0x2ce0, 0x2ce2)),
387 new DeltaSet(1, CharRanges.withMembers(
388 0x101, 0x103, 0x105, 0x107, 0x109, 0x10b, 0x10d, 0x10f, 0x111, 0x113,
389 0x115, 0x117, 0x119, 0x11b, 0x11d, 0x11f, 0x121, 0x123, 0x125, 0x127,
390 0x129, 0x12b, 0x12d, 0x12f, 0x133, 0x135, 0x137, 0x13a, 0x13c, 0x13e,
391 0x140, 0x142, 0x144, 0x146, 0x148, 0x14b, 0x14d, 0x14f, 0x151, 0x153,
392 0x155, 0x157, 0x159, 0x15b, 0x15d, 0x15f, 0x161, 0x163, 0x165, 0x167,
393 0x169, 0x16b, 0x16d, 0x16f, 0x171, 0x173, 0x175, 0x177, 0x17a, 0x17c,
394 0x17e, 0x183, 0x185, 0x188, 0x18c, 0x192, 0x199, 0x1a1, 0x1a3, 0x1a5,
395 0x1a8, 0x1ad, 0x1b0, 0x1b4, 0x1b6, 0x1b9, 0x1bd, 0x1c5, 0x1c8, 0x1cb,
396 0x1ce, 0x1d0, 0x1d2, 0x1d4, 0x1d6, 0x1d8, 0x1da, 0x1dc, 0x1df, 0x1e1,
397 0x1e3, 0x1e5, 0x1e7, 0x1e9, 0x1eb, 0x1ed, 0x1ef, 0x1f2, 0x1f5, 0x1f9,
398 0x1fb, 0x1fd, 0x1ff, 0x201, 0x203, 0x205, 0x207, 0x209, 0x20b, 0x20d,
399 0x20f, 0x211, 0x213, 0x215, 0x217, 0x219, 0x21b, 0x21d, 0x21f, 0x223,
400 0x225, 0x227, 0x229, 0x22b, 0x22d, 0x22f, 0x231, 0x233, 0x23c, 0x242,
401 0x247, 0x249, 0x24b, 0x24d, 0x24f, 0x3d9, 0x3db, 0x3dd, 0x3df, 0x3e1,
402 0x3e3, 0x3e5, 0x3e7, 0x3e9, 0x3eb, 0x3ed, 0x3ef, 0x3f8, 0x3fb, 0x461,
403 0x463, 0x465, 0x467, 0x469, 0x46b, 0x46d, 0x46f, 0x471, 0x473, 0x475,
404 0x477, 0x479, 0x47b, 0x47d, 0x47f, 0x481, 0x48b, 0x48d, 0x48f, 0x491,
405 0x493, 0x495, 0x497, 0x499, 0x49b, 0x49d, 0x49f, 0x4a1, 0x4a3, 0x4a5,
406 0x4a7, 0x4a9, 0x4ab, 0x4ad, 0x4af, 0x4b1, 0x4b3, 0x4b5, 0x4b7, 0x4b9,
407 0x4bb, 0x4bd, 0x4bf, 0x4c2, 0x4c4, 0x4c6, 0x4c8, 0x4ca, 0x4cc, 0x4ce,
408 0x4d1, 0x4d3, 0x4d5, 0x4d7, 0x4d9, 0x4db, 0x4dd, 0x4df, 0x4e1, 0x4e3,
409 0x4e5, 0x4e7, 0x4e9, 0x4eb, 0x4ed, 0x4ef, 0x4f1, 0x4f3, 0x4f5, 0x4f7,
410 0x4f9, 0x4fb, 0x4fd, 0x4ff, 0x501, 0x503, 0x505, 0x507, 0x509, 0x50b,
411 0x50d, 0x50f, 0x511, 0x513, 0x1e01, 0x1e03, 0x1e05, 0x1e07, 0x1e09,
412 0x1e0b, 0x1e0d, 0x1e0f, 0x1e11, 0x1e13, 0x1e15, 0x1e17, 0x1e19,
413 0x1e1b, 0x1e1d, 0x1e1f, 0x1e21, 0x1e23, 0x1e25, 0x1e27, 0x1e29,
414 0x1e2b, 0x1e2d, 0x1e2f, 0x1e31, 0x1e33, 0x1e35, 0x1e37, 0x1e39,
415 0x1e3b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cc5, 0x2cc7, 0x2cc9, 0x2ccb, 0x2ccd,
432 0x2ccf, 0x2cd1, 0x2cd3, 0x2cd5, 0x2cd7, 0x2cd9, 0x2cdb, 0x2cdd,
433 0x2cdf, 0x2ce1, 0x2ce3)),
434 new DeltaSet(2, CharRanges.withMembers(0x1c6, 0x1c9, 0x1cc, 0x1f3)),
435 new DeltaSet(7, CharRanges.withMembers(0x3f9, 0x1fec)),
436 new DeltaSet(8, CharRanges.withRanges(
437 0x1f08, 0x1f10, 0x1f18, 0x1f1e, 0x1f28, 0x1f30, 0x1f38, 0x1f40,
438 0x1f48, 0x1f4e, 0x1f59, 0x1f5a, 0x1f5b, 0x1f5c, 0x1f5d, 0x1f5e,
439 0x1f5f, 0x1f60, 0x1f68, 0x1f70, 0x1fb8, 0x1fba, 0x1fd8, 0x1fda,
440 0x1fe8, 0x1fea)),
441 new DeltaSet(15, CharRanges.withMembers(0x4cf)),
442 new DeltaSet(16, CharRanges.withRanges(0x2170, 0x2180)),
443 new DeltaSet(26, CharRanges.withRanges(0x24d0, 0x24ea)),
444 new DeltaSet(28, CharRanges.withMembers(0x214e)),
445 new DeltaSet(31, CharRanges.withMembers(0x3c2)),
446 new DeltaSet(32, CharRanges.withRanges(
447 0x61, 0x7b, 0xe0, 0xf7, 0xf8, 0xff, 0x3b1, 0x3c2, 0x3c3, 0x3cc,
448 0x430, 0x450, 0xff41, 0xff5b)),
449 new DeltaSet(37, CharRanges.withRanges(0x3ad, 0x3b0)),
450 new DeltaSet(38, CharRanges.withMembers(0x3ac)),
451 new DeltaSet(47, CharRanges.withMembers(0x3d5)),
452 new DeltaSet(48, CharRanges.withRanges(0x561, 0x587, 0x2c30, 0x2c5f)),
453 new DeltaSet(54, CharRanges.withMembers(0x3d6)),
454 new DeltaSet(56, CharRanges.withMembers(0x1f7)),
455 new DeltaSet(57, CharRanges.withMembers(0x3d1)),
456 new DeltaSet(59, CharRanges.withMembers(0x1e9b)),
457 new DeltaSet(62, CharRanges.withMembers(0x3d0)),
458 new DeltaSet(63, CharRanges.withRanges(0x3cd, 0x3cf)),
459 new DeltaSet(64, CharRanges.withMembers(0x3cc)),
460 new DeltaSet(69, CharRanges.withMembers(0x289)),
461 new DeltaSet(71, CharRanges.withMembers(0x28c)),
462 new DeltaSet(74, CharRanges.withRanges(0x1fba, 0x1fbc)),
463 new DeltaSet(79, CharRanges.withMembers(0x1dd)),
464 new DeltaSet(80, CharRanges.withRanges(0x3f1, 0x3f2, 0x450, 0x460)),
465 new DeltaSet(84, CharRanges.withMembers(0x399)),
466 new DeltaSet(86, CharRanges.withRanges(0x3f0, 0x3f1, 0x1fc8, 0x1fcc)),
467 new DeltaSet(96, CharRanges.withMembers(0x3f5)),
468 new DeltaSet(97, CharRanges.withMembers(0x1f6)),
469 new DeltaSet(100, CharRanges.withRanges(0x1fda, 0x1fdc)),
470 new DeltaSet(112, CharRanges.withRanges(0x1fea, 0x1fec)),
471 new DeltaSet(121, CharRanges.withMembers(0x178)),
472 new DeltaSet(126, CharRanges.withRanges(0x1ffa, 0x1ffc)),
473 new DeltaSet(128, CharRanges.withRanges(0x1ff8, 0x1ffa)),
474 new DeltaSet(130, CharRanges.withRanges(0x220, 0x221, 0x3fd, 0x400)),
475 new DeltaSet(163, CharRanges.withMembers(0x23d)),
476 new DeltaSet(195, CharRanges.withMembers(0x243)),
477 new DeltaSet(202, CharRanges.withMembers(0x259)),
478 new DeltaSet(203, CharRanges.withMembers(0x25b)),
479 new DeltaSet(205, CharRanges.withRanges(0x256, 0x258, 0x260, 0x261)),
480 new DeltaSet(206, CharRanges.withMembers(0x254)),
481 new DeltaSet(207, CharRanges.withMembers(0x263)),
482 new DeltaSet(209, CharRanges.withMembers(0x268)),
483 new DeltaSet(210, CharRanges.withMembers(0x253)),
484 new DeltaSet(211, CharRanges.withMembers(0x269, 0x26f)),
485 new DeltaSet(213, CharRanges.withMembers(0x272)),
486 new DeltaSet(214, CharRanges.withMembers(0x275)),
487 new DeltaSet(217, CharRanges.withRanges(0x28a, 0x28c)),
488 new DeltaSet(218, CharRanges.withMembers(0x280, 0x283, 0x288)),
489 new DeltaSet(219, CharRanges.withMembers(0x292)),
490 new DeltaSet(743, CharRanges.withMembers(0x39c)),
491 new DeltaSet(3814, CharRanges.withMembers(0x2c63)),
492 new DeltaSet(7205, CharRanges.withMembers(0x1fbe)),
493 new DeltaSet(7264, CharRanges.withRanges(0x2d00, 0x2d26)),
494 new DeltaSet(10727, CharRanges.withMembers(0x2c64)),
495 new DeltaSet(10743, CharRanges.withMembers(0x2c62)),
496 new DeltaSet(10792, CharRanges.withMembers(0x2c66)),
497 new DeltaSet(10795, CharRanges.withMembers(0x2c65))
498 );
499
500 private static final ImmutableList<DeltaSet> CANON_DELTA_SETS
501 = ImmutableList.of(
502 new DeltaSet(-10743, CharRanges.withMembers(0x26b)),
503 new DeltaSet(-10727, CharRanges.withMembers(0x27d)),
504 new DeltaSet(-3814, CharRanges.withMembers(0x1d7d)),
505 new DeltaSet(-743, CharRanges.withMembers(0xb5)),
506 new DeltaSet(-195, CharRanges.withMembers(0x180)),
507 new DeltaSet(-163, CharRanges.withMembers(0x19a)),
508 new DeltaSet(-130, CharRanges.withRanges(0x19e, 0x19f, 0x37b, 0x37e)),
509 new DeltaSet(-128, CharRanges.withRanges(0x1f78, 0x1f7a)),
510 new DeltaSet(-126, CharRanges.withRanges(0x1f7c, 0x1f7e)),
511 new DeltaSet(-121, CharRanges.withMembers(0xff)),
512 new DeltaSet(-112, CharRanges.withRanges(0x1f7a, 0x1f7c)),
513 new DeltaSet(-100, CharRanges.withRanges(0x1f76, 0x1f78)),
514 new DeltaSet(-97, CharRanges.withMembers(0x195)),
515 new DeltaSet(-86, CharRanges.withRanges(0x1f72, 0x1f76)),
516 new DeltaSet(-84, CharRanges.withMembers(0x345)),
517 new DeltaSet(-74, CharRanges.withRanges(0x1f70, 0x1f72)),
518 new DeltaSet(-56, CharRanges.withMembers(0x1bf)),
519 new DeltaSet(-8, CharRanges.withRanges(
520 0x1f00, 0x1f08, 0x1f10, 0x1f16, 0x1f20, 0x1f28, 0x1f30, 0x1f38,
521 0x1f40, 0x1f46, 0x1f51, 0x1f52, 0x1f53, 0x1f54, 0x1f55, 0x1f56,
522 0x1f57, 0x1f58, 0x1f60, 0x1f68, 0x1fb0, 0x1fb2, 0x1fd0, 0x1fd2,
523 0x1fe0, 0x1fe2)),
524 new DeltaSet(-7, CharRanges.withMembers(0x3f2, 0x1fe5)),
525 new DeltaSet(1, CharRanges.withMembers(
526 0x101, 0x103, 0x105, 0x107, 0x109, 0x10b, 0x10d, 0x10f, 0x111, 0x113,
527 0x115, 0x117, 0x119, 0x11b, 0x11d, 0x11f, 0x121, 0x123, 0x125, 0x127,
528 0x129, 0x12b, 0x12d, 0x12f, 0x133, 0x135, 0x137, 0x13a, 0x13c, 0x13e,
529 0x140, 0x142, 0x144, 0x146, 0x148, 0x14b, 0x14d, 0x14f, 0x151, 0x153,
530 0x155, 0x157, 0x159, 0x15b, 0x15d, 0x15f, 0x161, 0x163, 0x165, 0x167,
531 0x169, 0x16b, 0x16d, 0x16f, 0x171, 0x173, 0x175, 0x177, 0x17a, 0x17c,
532 0x17e, 0x183, 0x185, 0x188, 0x18c, 0x192, 0x199, 0x1a1, 0x1a3, 0x1a5,
533 0x1a8, 0x1ad, 0x1b0, 0x1b4, 0x1b6, 0x1b9, 0x1bd, 0x1c5, 0x1c8, 0x1cb,
534 0x1ce, 0x1d0, 0x1d2, 0x1d4, 0x1d6, 0x1d8, 0x1da, 0x1dc, 0x1df, 0x1e1,
535 0x1e3, 0x1e5, 0x1e7, 0x1e9, 0x1eb, 0x1ed, 0x1ef, 0x1f2, 0x1f5, 0x1f9,
536 0x1fb, 0x1fd, 0x1ff, 0x201, 0x203, 0x205, 0x207, 0x209, 0x20b, 0x20d,
537 0x20f, 0x211, 0x213, 0x215, 0x217, 0x219, 0x21b, 0x21d, 0x21f, 0x223,
538 0x225, 0x227, 0x229, 0x22b, 0x22d, 0x22f, 0x231, 0x233, 0x23c, 0x242,
539 0x247, 0x249, 0x24b, 0x24d, 0x24f, 0x3d9, 0x3db, 0x3dd, 0x3df, 0x3e1,
540 0x3e3, 0x3e5, 0x3e7, 0x3e9, 0x3eb, 0x3ed, 0x3ef, 0x3f8, 0x3fb, 0x461,
541 0x463, 0x465, 0x467, 0x469, 0x46b, 0x46d, 0x46f, 0x471, 0x473, 0x475,
542 0x477, 0x479, 0x47b, 0x47d, 0x47f, 0x481, 0x48b, 0x48d, 0x48f, 0x491,
543 0x493, 0x495, 0x497, 0x499, 0x49b, 0x49d, 0x49f, 0x4a1, 0x4a3, 0x4a5,
544 0x4a7, 0x4a9, 0x4ab, 0x4ad, 0x4af, 0x4b1, 0x4b3, 0x4b5, 0x4b7, 0x4b9,
545 0x4bb, 0x4bd, 0x4bf, 0x4c2, 0x4c4, 0x4c6, 0x4c8, 0x4ca, 0x4cc, 0x4ce,
546 0x4d1, 0x4d3, 0x4d5, 0x4d7, 0x4d9, 0x4db, 0x4dd, 0x4df, 0x4e1, 0x4e3,
547 0x4e5, 0x4e7, 0x4e9, 0x4eb, 0x4ed, 0x4ef, 0x4f1, 0x4f3, 0x4f5, 0x4f7,
548 0x4f9, 0x4fb, 0x4fd, 0x4ff, 0x501, 0x503, 0x505, 0x507, 0x509, 0x50b,
549 0x50d, 0x50f, 0x511, 0x513, 0x1e01, 0x1e03, 0x1e05, 0x1e07, 0x1e09,
550 0x1e0b, 0x1e0d, 0x1e0f, 0x1e11, 0x1e13, 0x1e15, 0x1e17, 0x1e19,
551 0x1e1b, 0x1e1d, 0x1e1f, 0x1e21, 0x1e23, 0x1e25, 0x1e27, 0x1e29,
552 0x1e2b, 0x1e2d, 0x1e2f, 0x1e31, 0x1e33, 0x1e35, 0x1e37, 0x1e39,
553 0x1e3b, 0x1e3d, 0x1e3f, 0x1e41, 0x1e43, 0x1e45, 0x1e47, 0x1e49,
554 0x1e4b, 0x1e4d, 0x1e4f, 0x1e51, 0x1e53, 0x1e55, 0x1e57, 0x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df, 0x2ce1, 0x2ce3)),
572 new DeltaSet(2, CharRanges.withMembers(0x1c6, 0x1c9, 0x1cc, 0x1f3)),
573 new DeltaSet(15, CharRanges.withMembers(0x4cf)),
574 new DeltaSet(16, CharRanges.withRanges(0x2170, 0x2180)),
575 new DeltaSet(26, CharRanges.withRanges(0x24d0, 0x24ea)),
576 new DeltaSet(28, CharRanges.withMembers(0x214e)),
577 new DeltaSet(31, CharRanges.withMembers(0x3c2)),
578 new DeltaSet(32, CharRanges.withRanges(
579 0x61, 0x7b, 0xe0, 0xf7, 0xf8, 0xff, 0x3b1, 0x3c2, 0x3c3, 0x3cc, 0x430,
580 0x450, 0xff41, 0xff5b)),
581 new DeltaSet(37, CharRanges.withRanges(0x3ad, 0x3b0)),
582 new DeltaSet(38, CharRanges.withMembers(0x3ac)),
583 new DeltaSet(47, CharRanges.withMembers(0x3d5)),
584 new DeltaSet(48, CharRanges.withRanges(0x561, 0x587, 0x2c30, 0x2c5f)),
585 new DeltaSet(54, CharRanges.withMembers(0x3d6)),
586 new DeltaSet(57, CharRanges.withMembers(0x3d1)),
587 new DeltaSet(59, CharRanges.withMembers(0x1e9b)),
588 new DeltaSet(62, CharRanges.withMembers(0x3d0)),
589 new DeltaSet(63, CharRanges.withRanges(0x3cd, 0x3cf)),
590 new DeltaSet(64, CharRanges.withMembers(0x3cc)),
591 new DeltaSet(69, CharRanges.withMembers(0x289)),
592 new DeltaSet(71, CharRanges.withMembers(0x28c)),
593 new DeltaSet(79, CharRanges.withMembers(0x1dd)),
594 new DeltaSet(80, CharRanges.withRanges(0x3f1, 0x3f2, 0x450, 0x460)),
595 new DeltaSet(86, CharRanges.withMembers(0x3f0)),
596 new DeltaSet(96, CharRanges.withMembers(0x3f5)),
597 new DeltaSet(202, CharRanges.withMembers(0x259)),
598 new DeltaSet(203, CharRanges.withMembers(0x25b)),
599 new DeltaSet(205, CharRanges.withRanges(0x256, 0x258, 0x260, 0x261)),
600 new DeltaSet(206, CharRanges.withMembers(0x254)),
601 new DeltaSet(207, CharRanges.withMembers(0x263)),
602 new DeltaSet(209, CharRanges.withMembers(0x268)),
603 new DeltaSet(210, CharRanges.withMembers(0x253)),
604 new DeltaSet(211, CharRanges.withMembers(0x269, 0x26f)),
605 new DeltaSet(213, CharRanges.withMembers(0x272)),
606 new DeltaSet(214, CharRanges.withMembers(0x275)),
607 new DeltaSet(217, CharRanges.withRanges(0x28a, 0x28c)),
608 new DeltaSet(218, CharRanges.withMembers(0x280, 0x283, 0x288)),
609 new DeltaSet(219, CharRanges.withMembers(0x292)),
610 new DeltaSet(7205, CharRanges.withMembers(0x1fbe)),
611 new DeltaSet(7264, CharRanges.withRanges(0x2d00, 0x2d26)),
612 new DeltaSet(10792, CharRanges.withMembers(0x2c66)),
613 new DeltaSet(10795, CharRanges.withMembers(0x2c65))
614 );
615
616
617 /**
618 * A group of code units such that for all cu in codeUnits, cu is equivalent,
619 * case-insensitively, to cu + delta.
620 */
621 private static final class DeltaSet {
622 final int delta;
623 final CharRanges codeUnits;
624
625 DeltaSet(int delta, CharRanges codeUnits) {
626 this.delta = delta;
627 this.codeUnits = codeUnits;
628 }
629 }
630
631 }