UCaseProps.java
21.1 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.impl.CharTrie;
import com.adobe.agl.impl.ICUBinary;
import com.adobe.agl.impl.ICUData;
import com.adobe.agl.impl.TrieIterator;
import com.adobe.agl.text.UTF16;
import com.adobe.agl.text.UnicodeSet;
import com.adobe.agl.util.RangeValueIterator;
import com.adobe.agl.util.ULocale;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
public final class UCaseProps {
private static UCaseProps gCsp = null;
private static UCaseProps gCspDummy = null;
private static final byte[] flagsOffset = new byte[]{0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
private int[] indexes;
private char[] exceptions;
private char[] unfold;
private CharTrie trie;
private static final byte[] FMT = new byte[]{99, 65, 83, 69};
public UCaseProps() throws IOException {
InputStream is = ICUData.getRequiredStream("data/icudt40b/ucase.icu");
BufferedInputStream b = new BufferedInputStream(is, 4096);
this.readData(b);
b.close();
is.close();
}
private final void readData(InputStream is) throws IOException {
int i;
DataInputStream inputStream = new DataInputStream(is);
ICUBinary.readHeader(inputStream, FMT, new IsAcceptable());
int count = inputStream.readInt();
if (count < 0) {
throw new IOException("indexes[0] too small in ucase.icu");
}
this.indexes = new int[count];
this.indexes[0] = count;
for (i = 1; i < count; ++i) {
this.indexes[i] = inputStream.readInt();
}
this.trie = new CharTrie(inputStream, null);
count = this.indexes[3];
if (count > 0) {
this.exceptions = new char[count];
for (i = 0; i < count; ++i) {
this.exceptions[i] = inputStream.readChar();
}
}
if ((count = this.indexes[4]) > 0) {
this.unfold = new char[count];
for (i = 0; i < count; ++i) {
this.unfold[i] = inputStream.readChar();
}
}
}
public static final synchronized UCaseProps getSingleton() throws IOException {
if (gCsp == null) {
gCsp = new UCaseProps();
}
return gCsp;
}
private UCaseProps(boolean makeDummy) {
this.indexes = new int[16];
this.indexes[0] = 16;
this.trie = new CharTrie(0, 0, null);
}
public static final synchronized UCaseProps getDummy() {
if (gCspDummy == null) {
gCspDummy = new UCaseProps(true);
}
return gCspDummy;
}
public final void addPropertyStarts(UnicodeSet set) {
TrieIterator iter = new TrieIterator(this.trie);
RangeValueIterator.Element element = new RangeValueIterator.Element();
while (iter.next(element)) {
set.add(element.start);
}
}
private static final int getExceptionsOffset(int props) {
return props >> 4;
}
private static final boolean propsHasException(int props) {
return (props & 8) != 0;
}
private static final boolean hasSlot(int flags, int index) {
return (flags & 1 << index) != 0;
}
private static final byte slotOffset(int flags, int index) {
return flagsOffset[flags & (1 << index) - 1];
}
private final long getSlotValueAndOffset(int excWord, int index, int excOffset) {
long value;
if ((excWord & 256) == 0) {
value = this.exceptions[excOffset += UCaseProps.slotOffset(excWord, index)];
} else {
excOffset += 2 * UCaseProps.slotOffset(excWord, index);
value = this.exceptions[excOffset++];
value = value << 16 | (long)this.exceptions[excOffset];
}
return value | (long)excOffset << 32;
}
private final int getSlotValue(int excWord, int index, int excOffset) {
int value;
if ((excWord & 256) == 0) {
value = this.exceptions[excOffset += UCaseProps.slotOffset(excWord, index)];
} else {
excOffset += 2 * UCaseProps.slotOffset(excWord, index);
value = this.exceptions[excOffset++];
value = value << 16 | this.exceptions[excOffset];
}
return value;
}
public final int tolower(int c) {
char props = this.trie.getCodePointValue(c);
if (!UCaseProps.propsHasException(props)) {
if (UCaseProps.getTypeFromProps(props) >= 2) {
c += UCaseProps.getDelta(props);
}
} else {
char excWord;
int excOffset = UCaseProps.getExceptionsOffset(props);
if (UCaseProps.hasSlot(excWord = this.exceptions[excOffset++], 0)) {
c = this.getSlotValue(excWord, 0, excOffset);
}
}
return c;
}
public final void addCaseClosure(int c, UnicodeSet set) {
switch (c) {
case 73: {
set.add(105);
return;
}
case 105: {
set.add(73);
return;
}
case 304: {
set.add("i\u0307");
return;
}
case 305: {
return;
}
}
char props = this.trie.getCodePointValue(c);
if (!UCaseProps.propsHasException(props)) {
int delta;
if (UCaseProps.getTypeFromProps(props) != 0 && (delta = UCaseProps.getDelta(props)) != 0) {
set.add(c + delta);
}
} else {
int index;
int closureLength;
long value;
int closureOffset;
int excOffset = UCaseProps.getExceptionsOffset(props);
char excWord = this.exceptions[excOffset++];
int excOffset0 = excOffset;
for (index = 0; index <= 3; ++index) {
if (!UCaseProps.hasSlot(excWord, index)) continue;
excOffset = excOffset0;
c = this.getSlotValue(excWord, index, excOffset);
set.add(c);
}
if (UCaseProps.hasSlot(excWord, 6)) {
excOffset = excOffset0;
value = this.getSlotValueAndOffset(excWord, 6, excOffset);
closureLength = (int)value & 15;
closureOffset = (int)(value >> 32) + 1;
} else {
closureLength = 0;
closureOffset = 0;
}
if (UCaseProps.hasSlot(excWord, 7)) {
excOffset = excOffset0;
value = this.getSlotValueAndOffset(excWord, 7, excOffset);
int fullLength = (int)value;
excOffset = (int)(value >> 32) + 1;
excOffset += (fullLength &= 65535) & 15;
int length = (fullLength >>= 4) & 15;
if (length != 0) {
set.add(new String(this.exceptions, excOffset, length));
excOffset += length;
}
excOffset += (fullLength >>= 4) & 15;
closureOffset = excOffset += (fullLength >>= 4);
}
for (index = 0; index < closureLength; index += UTF16.getCharCount((int)c)) {
c = UTF16.charAt(this.exceptions, closureOffset, this.exceptions.length, index);
set.add(c);
}
}
}
private final int strcmpMax(String s, int unfoldOffset, int max) {
int length = s.length();
max -= length;
int i1 = 0;
do {
char c2;
int c1 = s.charAt(i1++);
if ((c2 = this.unfold[unfoldOffset++]) == '\u0000') {
return 1;
}
if ((c1 -= c2) == 0) continue;
return c1;
} while (--length > 0);
if (max == 0 || this.unfold[unfoldOffset] == '\u0000') {
return 0;
}
return - max;
}
public final boolean addStringCaseClosure(String s, UnicodeSet set) {
if (this.unfold == null || s == null) {
return false;
}
int length = s.length();
if (length <= 1) {
return false;
}
int unfoldRows = this.unfold[0];
char unfoldRowWidth = this.unfold[1];
int unfoldStringWidth = this.unfold[2];
if (length > unfoldStringWidth) {
return false;
}
int start = 0;
int limit = unfoldRows;
while (start < limit) {
int i = (start + limit) / 2;
int unfoldOffset = (i + 1) * unfoldRowWidth;
int result = this.strcmpMax(s, unfoldOffset, unfoldStringWidth);
if (result == 0) {
int c;
for (i = unfoldStringWidth; i < unfoldRowWidth && this.unfold[unfoldOffset + i] != '\u0000'; i += UTF16.getCharCount((int)c)) {
c = UTF16.charAt(this.unfold, unfoldOffset, this.unfold.length, i);
set.add(c);
this.addCaseClosure(c, set);
}
return true;
}
if (result < 0) {
limit = i;
continue;
}
start = i + 1;
}
return false;
}
public final int getType(int c) {
return UCaseProps.getTypeFromProps(this.trie.getCodePointValue(c));
}
public final int getDotType(int c) {
char props = this.trie.getCodePointValue(c);
if (!UCaseProps.propsHasException(props)) {
return props & 48;
}
return this.exceptions[UCaseProps.getExceptionsOffset(props)] >> 8 & 48;
}
public final boolean isSoftDotted(int c) {
return this.getDotType(c) == 16;
}
public final boolean isCaseSensitive(int c) {
return (this.trie.getCodePointValue(c) & 4) != 0;
}
private static final int getCaseLocale(ULocale locale, int[] locCache) {
int result;
if (locCache != null && (result = locCache[0]) != 0) {
return result;
}
result = 1;
String language = locale.getLanguage();
if (language.equals("tr") || language.equals("tur") || language.equals("az") || language.equals("aze")) {
result = 2;
} else if (language.equals("lt") || language.equals("lit")) {
result = 3;
}
if (locCache != null) {
locCache[0] = result;
}
return result;
}
private final boolean isFollowedByCasedLetter(ContextIterator iter, int dir) {
int c;
if (iter == null) {
return false;
}
iter.reset(dir);
while ((c = iter.next()) >= 0) {
char props = this.trie.getCodePointValue(c);
if (UCaseProps.getTypeFromProps(props) != 0) {
return true;
}
if (c == 775 || (props & 72) == 64) continue;
return false;
}
return false;
}
private final boolean isPrecededBySoftDotted(ContextIterator iter) {
int c;
if (iter == null) {
return false;
}
iter.reset(-1);
while ((c = iter.next()) >= 0) {
int dotType = this.getDotType(c);
if (dotType == 16) {
return true;
}
if (dotType == 48) continue;
return false;
}
return false;
}
private final boolean isPrecededBy_I(ContextIterator iter) {
int c;
if (iter == null) {
return false;
}
iter.reset(-1);
while ((c = iter.next()) >= 0) {
if (c == 73) {
return true;
}
int dotType = this.getDotType(c);
if (dotType == 48) continue;
return false;
}
return false;
}
private final boolean isFollowedByMoreAbove(ContextIterator iter) {
int c;
if (iter == null) {
return false;
}
iter.reset(1);
while ((c = iter.next()) >= 0) {
int dotType = this.getDotType(c);
if (dotType == 32) {
return true;
}
if (dotType == 48) continue;
return false;
}
return false;
}
private final boolean isFollowedByDotAbove(ContextIterator iter) {
int c;
if (iter == null) {
return false;
}
iter.reset(1);
while ((c = iter.next()) >= 0) {
if (c == 775) {
return true;
}
int dotType = this.getDotType(c);
if (dotType == 48) continue;
return false;
}
return false;
}
public final int toFullLower(int c, ContextIterator iter, StringBuffer out, ULocale locale, int[] locCache) {
int result = c;
char props = this.trie.getCodePointValue(c);
if (!UCaseProps.propsHasException(props)) {
if (UCaseProps.getTypeFromProps(props) >= 2) {
result = c + UCaseProps.getDelta(props);
}
} else {
int full;
long value;
int excOffset = UCaseProps.getExceptionsOffset(props);
char excWord = this.exceptions[excOffset++];
int excOffset2 = excOffset;
if ((excWord & 16384) != 0) {
int loc = UCaseProps.getCaseLocale(locale, locCache);
if (loc == 3 && ((c == 73 || c == 74 || c == 302) && this.isFollowedByMoreAbove(iter) || c == 204 || c == 205 || c == 296)) {
switch (c) {
case 73: {
out.append("i\u0307");
return 2;
}
case 74: {
out.append("j\u0307");
return 2;
}
case 302: {
out.append("\u012f\u0307");
return 2;
}
case 204: {
out.append("i\u0307\u0300");
return 3;
}
case 205: {
out.append("i\u0307\u0301");
return 3;
}
case 296: {
out.append("i\u0307\u0303");
return 3;
}
}
return 0;
}
if (loc == 2 && c == 304) {
return 105;
}
if (loc == 2 && c == 775 && this.isPrecededBy_I(iter)) {
return 0;
}
if (loc == 2 && c == 73 && !this.isFollowedByDotAbove(iter)) {
return 305;
}
if (c == 304) {
out.append("i\u0307");
return 2;
}
if (c == 931 && !this.isFollowedByCasedLetter(iter, 1) && this.isFollowedByCasedLetter(iter, -1)) {
return 962;
}
} else if (UCaseProps.hasSlot(excWord, 7) && (full = (int)(value = this.getSlotValueAndOffset(excWord, 7, excOffset)) & 15) != 0) {
excOffset = (int)(value >> 32) + 1;
out.append(new String(this.exceptions, excOffset, full));
return full;
}
if (UCaseProps.hasSlot(excWord, 0)) {
result = this.getSlotValue(excWord, 0, excOffset2);
}
}
return result == c ? ~ result : result;
}
private final int toUpperOrTitle(int c, ContextIterator iter, StringBuffer out, ULocale locale, int[] locCache, boolean upperNotTitle) {
int result = c;
char props = this.trie.getCodePointValue(c);
if (!UCaseProps.propsHasException(props)) {
if (UCaseProps.getTypeFromProps(props) == 1) {
result = c + UCaseProps.getDelta(props);
}
} else {
int index;
int excOffset = UCaseProps.getExceptionsOffset(props);
char excWord = this.exceptions[excOffset++];
int excOffset2 = excOffset;
if ((excWord & 16384) != 0) {
int loc = UCaseProps.getCaseLocale(locale, locCache);
if (loc == 2 && c == 105) {
return 304;
}
if (loc == 3 && c == 775 && this.isPrecededBySoftDotted(iter)) {
return 0;
}
} else if (UCaseProps.hasSlot(excWord, 7)) {
long value = this.getSlotValueAndOffset(excWord, 7, excOffset);
int full = (int)value & 65535;
excOffset = (int)(value >> 32) + 1;
excOffset += full & 15;
excOffset += (full >>= 4) & 15;
full >>= 4;
if (upperNotTitle) {
full &= 15;
} else {
excOffset += full & 15;
full = full >> 4 & 15;
}
if (full != 0) {
out.append(new String(this.exceptions, excOffset, full));
return full;
}
}
if (!upperNotTitle && UCaseProps.hasSlot(excWord, 3)) {
index = 3;
} else if (UCaseProps.hasSlot(excWord, 2)) {
index = 2;
} else {
return ~ c;
}
result = this.getSlotValue(excWord, index, excOffset2);
}
return result == c ? ~ result : result;
}
public final int toFullUpper(int c, ContextIterator iter, StringBuffer out, ULocale locale, int[] locCache) {
return this.toUpperOrTitle(c, iter, out, locale, locCache, true);
}
public final int toFullTitle(int c, ContextIterator iter, StringBuffer out, ULocale locale, int[] locCache) {
return this.toUpperOrTitle(c, iter, out, locale, locCache, false);
}
public final int toFullFolding(int c, StringBuffer out, int options) {
int result = c;
char props = this.trie.getCodePointValue(c);
if (!UCaseProps.propsHasException(props)) {
if (UCaseProps.getTypeFromProps(props) >= 2) {
result = c + UCaseProps.getDelta(props);
}
} else {
int index;
int excOffset = UCaseProps.getExceptionsOffset(props);
char excWord = this.exceptions[excOffset++];
int excOffset2 = excOffset;
if ((excWord & 32768) != 0) {
if ((options & 255) == 0) {
if (c == 73) {
return 105;
}
if (c == 304) {
out.append("i\u0307");
return 2;
}
} else {
if (c == 73) {
return 305;
}
if (c == 304) {
return 105;
}
}
} else if (UCaseProps.hasSlot(excWord, 7)) {
long value = this.getSlotValueAndOffset(excWord, 7, excOffset);
int full = (int)value & 65535;
excOffset = (int)(value >> 32) + 1;
excOffset += full & 15;
if ((full = full >> 4 & 15) != 0) {
out.append(new String(this.exceptions, excOffset, full));
return full;
}
}
if (UCaseProps.hasSlot(excWord, 1)) {
index = 1;
} else if (UCaseProps.hasSlot(excWord, 0)) {
index = 0;
} else {
return ~ c;
}
result = this.getSlotValue(excWord, index, excOffset2);
}
return result == c ? ~ result : result;
}
private static final int getTypeFromProps(int props) {
return props & 3;
}
private static final int getDelta(int props) {
return (short)props >> 6;
}
public static interface ContextIterator {
public void reset(int var1);
public int next();
}
private final class IsAcceptable
implements ICUBinary.Authenticate {
private IsAcceptable() {
}
public boolean isDataVersionAcceptable(byte[] version) {
return version[0] == 1 && version[2] == 5 && version[3] == 2;
}
}
}