Normalizer.java
12.2 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.text;
import com.adobe.agl.impl.NormalizerImpl;
import com.adobe.agl.text.UCharacterIterator;
import com.adobe.agl.text.UTF16;
import com.adobe.agl.text.UnicodeSet;
import com.adobe.agl.util.VersionInfo;
public final class Normalizer
implements Cloneable {
private char[] buffer;
private UCharacterIterator text;
public static final Mode NONE = new Mode(1);
public static final Mode NFD = new NFDMode(2);
public static final Mode NFKD = new NFKDMode(3);
public static final Mode NFC;
public static final Mode DEFAULT;
public static final Mode NFKC;
public static final Mode FCD;
public static final Mode NO_OP;
public static final Mode COMPOSE;
public static final Mode COMPOSE_COMPAT;
public static final Mode DECOMP;
public static final Mode DECOMP_COMPAT;
public static final QuickCheckResult NO;
public static final QuickCheckResult YES;
public static final QuickCheckResult MAYBE;
public Object clone() {
try {
Normalizer copy = (Normalizer)super.clone();
copy.text = (UCharacterIterator)this.text.clone();
if (this.buffer != null) {
copy.buffer = new char[this.buffer.length];
System.arraycopy(this.buffer, 0, copy.buffer, 0, this.buffer.length);
}
return copy;
}
catch (CloneNotSupportedException e) {
throw new IllegalStateException(e.toString());
}
}
public static String compose(String str, boolean compat) {
return Normalizer.compose(str, compat, 0);
}
public static String compose(String str, boolean compat, int options) {
char[] dest = new char[str.length() * 2];
int destSize = 0;
char[] src = str.toCharArray();
UnicodeSet nx = NormalizerImpl.getNX(options);
options &= -12544;
if (compat) {
options |= 4096;
}
while ((destSize = NormalizerImpl.compose(src, 0, src.length, dest, 0, dest.length, options, nx)) > dest.length) {
dest = new char[destSize];
}
return new String(dest, 0, destSize);
}
public static String decompose(String str, boolean compat) {
return Normalizer.decompose(str, compat, 0);
}
public static String decompose(String str, boolean compat, int options) {
char[] dest = new char[str.length() * 3];
int[] trailCC = new int[1];
int destSize = 0;
UnicodeSet nx = NormalizerImpl.getNX(options);
while ((destSize = NormalizerImpl.decompose(str.toCharArray(), 0, str.length(), dest, 0, dest.length, compat, trailCC, nx)) > dest.length) {
dest = new char[destSize];
}
return new String(dest, 0, destSize);
}
private static String makeFCD(String src, int options) {
int srcLen = src.length();
char[] dest = new char[3 * srcLen];
int length = 0;
UnicodeSet nx = NormalizerImpl.getNX(options);
while ((length = NormalizerImpl.makeFCD(src.toCharArray(), 0, srcLen, dest, 0, dest.length, nx)) > dest.length) {
dest = new char[length];
}
return new String(dest, 0, length);
}
public static String normalize(String str, Mode mode, int options) {
return mode.normalize(str, options);
}
public static String normalize(String src, Mode mode) {
return Normalizer.normalize(src, mode, 0);
}
public static String normalize(int char32, Mode mode) {
return Normalizer.normalize(UTF16.valueOf(char32), mode, 0);
}
public static QuickCheckResult quickCheck(String source, Mode mode, int options) {
return mode.quickCheck(source.toCharArray(), 0, source.length(), true, NormalizerImpl.getNX(options));
}
public static int compare(char[] s1, int s1Start, int s1Limit, char[] s2, int s2Start, int s2Limit, int options) {
return Normalizer.internalCompare(s1, s1Start, s1Limit, s2, s2Start, s2Limit, options);
}
public static int compare(String s1, String s2, int options) {
return Normalizer.compare(s1.toCharArray(), 0, s1.length(), s2.toCharArray(), 0, s2.length(), options);
}
public static boolean isNFSkippable(int c, Mode mode) {
return mode.isNFSkippable(c);
}
private static int internalCompare(char[] s1, int s1Start, int s1Limit, char[] s2, int s2Start, int s2Limit, int options) {
Mode mode;
char[] fcd1 = new char[300];
char[] fcd2 = new char[300];
if (s1 == null || s1Start < 0 || s1Limit < 0 || s2 == null || s2Start < 0 || s2Limit < 0 || s1Limit < s1Start || s2Limit < s2Start) {
throw new IllegalArgumentException();
}
UnicodeSet nx = NormalizerImpl.getNX(options >> 20);
int result = 0;
if (((options |= 524288) & 1) > 0) {
mode = NFD;
options &= -131073;
} else {
mode = FCD;
}
if ((options & 131072) == 0) {
char[] dest;
boolean isFCD2;
boolean isFCD1 = YES == mode.quickCheck(s1, s1Start, s1Limit, true, nx);
boolean bl = isFCD2 = YES == mode.quickCheck(s2, s2Start, s2Limit, true, nx);
if (!isFCD1) {
int fcdLen1 = mode.normalize(s1, 0, s1.length, fcd1, 0, fcd1.length, nx);
if (fcdLen1 > fcd1.length) {
dest = new char[fcdLen1];
fcdLen1 = mode.normalize(s1, 0, s1.length, dest, 0, dest.length, nx);
s1 = dest;
} else {
s1 = fcd1;
}
s1Limit = fcdLen1;
s1Start = 0;
}
if (!isFCD2) {
int fcdLen2 = mode.normalize(s2, s2Start, s2Limit, fcd2, 0, fcd2.length, nx);
if (fcdLen2 > fcd2.length) {
dest = new char[fcdLen2];
fcdLen2 = mode.normalize(s2, s2Start, s2Limit, dest, 0, dest.length, nx);
s2 = dest;
} else {
s2 = fcd2;
}
s2Limit = fcdLen2;
s2Start = 0;
}
}
result = NormalizerImpl.cmpEquivFold(s1, s1Start, s1Limit, s2, s2Start, s2Limit, options);
return result;
}
static VersionInfo getUnicodeVersion() {
return NormalizerImpl.getUnicodeVersion();
}
static {
DEFAULT = Normalizer.NFC = new NFCMode(4);
NFKC = new NFKCMode(5);
FCD = new FCDMode(6);
NO_OP = NONE;
COMPOSE = NFC;
COMPOSE_COMPAT = NFKC;
DECOMP = NFD;
DECOMP_COMPAT = NFKD;
NO = new QuickCheckResult(0);
YES = new QuickCheckResult(1);
MAYBE = new QuickCheckResult(2);
}
public static final class QuickCheckResult {
private QuickCheckResult(int value) {
}
}
private static final class FCDMode
extends Mode {
private FCDMode(int value) {
super(value);
}
protected int normalize(char[] src, int srcStart, int srcLimit, char[] dest, int destStart, int destLimit, UnicodeSet nx) {
return NormalizerImpl.makeFCD(src, srcStart, srcLimit, dest, destStart, destLimit, nx);
}
protected String normalize(String src, int options) {
return Normalizer.makeFCD(src, options);
}
protected QuickCheckResult quickCheck(char[] src, int start, int limit, boolean allowMaybe, UnicodeSet nx) {
return NormalizerImpl.checkFCD(src, start, limit, nx) ? Normalizer.YES : Normalizer.NO;
}
protected boolean isNFSkippable(int c) {
return NormalizerImpl.getFCD16(c) > 1;
}
}
private static final class NFKCMode
extends Mode {
private NFKCMode(int value) {
super(value);
}
protected int normalize(char[] src, int srcStart, int srcLimit, char[] dest, int destStart, int destLimit, UnicodeSet nx) {
return NormalizerImpl.compose(src, srcStart, srcLimit, dest, destStart, destLimit, 4096, nx);
}
protected String normalize(String src, int options) {
return Normalizer.compose(src, true, options);
}
protected QuickCheckResult quickCheck(char[] src, int start, int limit, boolean allowMaybe, UnicodeSet nx) {
return NormalizerImpl.quickCheck(src, start, limit, NormalizerImpl.getFromIndexesArr(7), 34, 4096, allowMaybe, nx);
}
protected boolean isNFSkippable(int c) {
return NormalizerImpl.isNFSkippable(c, this, 65474);
}
}
private static final class NFCMode
extends Mode {
private NFCMode(int value) {
super(value);
}
protected int normalize(char[] src, int srcStart, int srcLimit, char[] dest, int destStart, int destLimit, UnicodeSet nx) {
return NormalizerImpl.compose(src, srcStart, srcLimit, dest, destStart, destLimit, 0, nx);
}
protected String normalize(String src, int options) {
return Normalizer.compose(src, false, options);
}
protected QuickCheckResult quickCheck(char[] src, int start, int limit, boolean allowMaybe, UnicodeSet nx) {
return NormalizerImpl.quickCheck(src, start, limit, NormalizerImpl.getFromIndexesArr(6), 17, 0, allowMaybe, nx);
}
protected boolean isNFSkippable(int c) {
return NormalizerImpl.isNFSkippable(c, this, 65473);
}
}
private static final class NFKDMode
extends Mode {
private NFKDMode(int value) {
super(value);
}
protected int normalize(char[] src, int srcStart, int srcLimit, char[] dest, int destStart, int destLimit, UnicodeSet nx) {
int[] trailCC = new int[1];
return NormalizerImpl.decompose(src, srcStart, srcLimit, dest, destStart, destLimit, true, trailCC, nx);
}
protected String normalize(String src, int options) {
return Normalizer.decompose(src, true);
}
protected QuickCheckResult quickCheck(char[] src, int start, int limit, boolean allowMaybe, UnicodeSet nx) {
return NormalizerImpl.quickCheck(src, start, limit, NormalizerImpl.getFromIndexesArr(9), 8, 4096, allowMaybe, nx);
}
protected boolean isNFSkippable(int c) {
return NormalizerImpl.isNFSkippable(c, this, 65288);
}
}
private static final class NFDMode
extends Mode {
private NFDMode(int value) {
super(value);
}
protected int normalize(char[] src, int srcStart, int srcLimit, char[] dest, int destStart, int destLimit, UnicodeSet nx) {
int[] trailCC = new int[1];
return NormalizerImpl.decompose(src, srcStart, srcLimit, dest, destStart, destLimit, false, trailCC, nx);
}
protected String normalize(String src, int options) {
return Normalizer.decompose(src, false);
}
protected QuickCheckResult quickCheck(char[] src, int start, int limit, boolean allowMaybe, UnicodeSet nx) {
return NormalizerImpl.quickCheck(src, start, limit, NormalizerImpl.getFromIndexesArr(8), 4, 0, allowMaybe, nx);
}
protected boolean isNFSkippable(int c) {
return NormalizerImpl.isNFSkippable(c, this, 65284);
}
}
public static class Mode {
private Mode(int value) {
}
protected int normalize(char[] src, int srcStart, int srcLimit, char[] dest, int destStart, int destLimit, UnicodeSet nx) {
int srcLen = srcLimit - srcStart;
int destLen = destLimit - destStart;
if (srcLen > destLen) {
return srcLen;
}
System.arraycopy(src, srcStart, dest, destStart, srcLen);
return srcLen;
}
protected String normalize(String src, int options) {
return src;
}
protected QuickCheckResult quickCheck(char[] src, int start, int limit, boolean allowMaybe, UnicodeSet nx) {
if (allowMaybe) {
return Normalizer.MAYBE;
}
return Normalizer.NO;
}
protected boolean isNFSkippable(int c) {
return true;
}
}
}