RBBIDataWrapper.java
11.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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.text;
import com.adobe.agl.impl.CharTrie;
import com.adobe.agl.impl.Trie;
import com.adobe.agl.text.RuleBasedBreakIterator;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
final class RBBIDataWrapper {
RBBIDataHeader fHeader;
short[] fFTable;
short[] fRTable;
short[] fSFTable;
short[] fSRTable;
CharTrie fTrie;
String fRuleSource;
int[] fStatusTable;
static TrieFoldingFunc fTrieFoldingFunc = new TrieFoldingFunc();
int getRowIndex(int state) {
return 8 + state * (this.fHeader.fCatCount + 4);
}
RBBIDataWrapper() {
}
static RBBIDataWrapper get(InputStream is) throws IOException {
int i;
DataInputStream dis = new DataInputStream(new BufferedInputStream(is));
RBBIDataWrapper This = new RBBIDataWrapper();
dis.skip(128);
This.fHeader = new RBBIDataHeader();
This.fHeader.fMagic = dis.readInt();
This.fHeader.fVersion = dis.readInt();
This.fHeader.fFormatVersion[0] = (byte)(This.fHeader.fVersion >> 24);
This.fHeader.fFormatVersion[1] = (byte)(This.fHeader.fVersion >> 16);
This.fHeader.fFormatVersion[2] = (byte)(This.fHeader.fVersion >> 8);
This.fHeader.fFormatVersion[3] = (byte)This.fHeader.fVersion;
This.fHeader.fLength = dis.readInt();
This.fHeader.fCatCount = dis.readInt();
This.fHeader.fFTable = dis.readInt();
This.fHeader.fFTableLen = dis.readInt();
This.fHeader.fRTable = dis.readInt();
This.fHeader.fRTableLen = dis.readInt();
This.fHeader.fSFTable = dis.readInt();
This.fHeader.fSFTableLen = dis.readInt();
This.fHeader.fSRTable = dis.readInt();
This.fHeader.fSRTableLen = dis.readInt();
This.fHeader.fTrie = dis.readInt();
This.fHeader.fTrieLen = dis.readInt();
This.fHeader.fRuleSource = dis.readInt();
This.fHeader.fRuleSourceLen = dis.readInt();
This.fHeader.fStatusTable = dis.readInt();
This.fHeader.fStatusTableLen = dis.readInt();
dis.skip(24);
if (This.fHeader.fMagic != 45472 || This.fHeader.fVersion != 1 && This.fHeader.fFormatVersion[0] != 3) {
throw new IOException("Break Iterator Rule Data Magic Number Incorrect, or unsupported data version.");
}
int pos = 96;
if (This.fHeader.fFTable < pos || This.fHeader.fFTable > This.fHeader.fLength) {
throw new IOException("Break iterator Rule data corrupt");
}
dis.skip(This.fHeader.fFTable - pos);
pos = This.fHeader.fFTable;
This.fFTable = new short[This.fHeader.fFTableLen / 2];
for (i = 0; i < This.fFTable.length; ++i) {
This.fFTable[i] = dis.readShort();
pos += 2;
}
dis.skip(This.fHeader.fRTable - pos);
pos = This.fHeader.fRTable;
This.fRTable = new short[This.fHeader.fRTableLen / 2];
for (i = 0; i < This.fRTable.length; ++i) {
This.fRTable[i] = dis.readShort();
pos += 2;
}
if (This.fHeader.fSFTableLen > 0) {
dis.skip(This.fHeader.fSFTable - pos);
pos = This.fHeader.fSFTable;
This.fSFTable = new short[This.fHeader.fSFTableLen / 2];
for (i = 0; i < This.fSFTable.length; ++i) {
This.fSFTable[i] = dis.readShort();
pos += 2;
}
}
if (This.fHeader.fSRTableLen > 0) {
dis.skip(This.fHeader.fSRTable - pos);
pos = This.fHeader.fSRTable;
This.fSRTable = new short[This.fHeader.fSRTableLen / 2];
for (i = 0; i < This.fSRTable.length; ++i) {
This.fSRTable[i] = dis.readShort();
pos += 2;
}
}
dis.skip(This.fHeader.fTrie - pos);
pos = This.fHeader.fTrie;
dis.mark(This.fHeader.fTrieLen + 100);
This.fTrie = new CharTrie(dis, fTrieFoldingFunc);
dis.reset();
if (pos > This.fHeader.fStatusTable) {
throw new IOException("Break iterator Rule data corrupt");
}
dis.skip(This.fHeader.fStatusTable - pos);
pos = This.fHeader.fStatusTable;
This.fStatusTable = new int[This.fHeader.fStatusTableLen / 4];
for (i = 0; i < This.fStatusTable.length; ++i) {
This.fStatusTable[i] = dis.readInt();
pos += 4;
}
if (pos > This.fHeader.fRuleSource) {
throw new IOException("Break iterator Rule data corrupt");
}
dis.skip(This.fHeader.fRuleSource - pos);
pos = This.fHeader.fRuleSource;
StringBuffer sb = new StringBuffer(This.fHeader.fRuleSourceLen / 2);
for (i = 0; i < This.fHeader.fRuleSourceLen; i += 2) {
sb.append(dis.readChar());
pos += 2;
}
This.fRuleSource = sb.toString();
if (RuleBasedBreakIterator.fDebugEnv != null && RuleBasedBreakIterator.fDebugEnv.indexOf("data") >= 0) {
This.dump();
}
return This;
}
static final int getNumStates(short[] table) {
short hi = table[0];
short lo = table[1];
int val = (hi << 16) + (lo & 65535);
return val;
}
void dump() {
System.out.println("RBBI Data Wrapper dump ...");
System.out.println();
System.out.println("Forward State Table");
this.dumpTable(this.fFTable);
System.out.println("Reverse State Table");
this.dumpTable(this.fRTable);
System.out.println("Forward Safe Points Table");
this.dumpTable(this.fSFTable);
System.out.println("Reverse Safe Points Table");
this.dumpTable(this.fSRTable);
this.dumpCharCategories();
System.out.println("Source Rules: " + this.fRuleSource);
}
public static String intToString(int n, int width) {
StringBuffer dest = new StringBuffer(width);
dest.append(n);
while (dest.length() < width) {
dest.insert(0, ' ');
}
return dest.toString();
}
public static String intToHexString(int n, int width) {
StringBuffer dest = new StringBuffer(width);
dest.append(Integer.toHexString(n));
while (dest.length() < width) {
dest.insert(0, ' ');
}
return dest.toString();
}
private void dumpTable(short[] table) {
if (table == null) {
System.out.println(" -- null -- ");
} else {
int n;
String header = " Row Acc Look Tag";
for (n = 0; n < this.fHeader.fCatCount; ++n) {
header = header + RBBIDataWrapper.intToString(n, 5);
}
System.out.println(header);
for (n = 0; n < header.length(); ++n) {
System.out.print("-");
}
System.out.println();
for (int state = 0; state < RBBIDataWrapper.getNumStates(table); ++state) {
this.dumpRow(table, state);
}
System.out.println();
}
}
private void dumpRow(short[] table, int state) {
StringBuffer dest = new StringBuffer(this.fHeader.fCatCount * 5 + 20);
dest.append(RBBIDataWrapper.intToString(state, 4));
int row = this.getRowIndex(state);
if (table[row + 0] != 0) {
dest.append(RBBIDataWrapper.intToString(table[row + 0], 5));
} else {
dest.append(" ");
}
if (table[row + 1] != 0) {
dest.append(RBBIDataWrapper.intToString(table[row + 1], 5));
} else {
dest.append(" ");
}
dest.append(RBBIDataWrapper.intToString(table[row + 2], 5));
for (int col = 0; col < this.fHeader.fCatCount; ++col) {
dest.append(RBBIDataWrapper.intToString(table[row + 4 + col], 5));
}
System.out.println(dest);
}
private void dumpCharCategories() {
int category;
int n = this.fHeader.fCatCount;
String[] catStrings = new String[n + 1];
int rangeStart = 0;
int rangeEnd = 0;
int lastCat = -1;
int[] lastNewline = new int[n + 1];
for (category = 0; category <= this.fHeader.fCatCount; ++category) {
catStrings[category] = "";
}
System.out.println("\nCharacter Categories");
System.out.println("--------------------");
for (int char32 = 0; char32 <= 1114111; ++char32) {
category = this.fTrie.getCodePointValue(char32);
if ((category &= -16385) < 0 || category > this.fHeader.fCatCount) {
System.out.println("Error, bad category " + Integer.toHexString(category) + " for char " + Integer.toHexString(char32));
break;
}
if (category == lastCat) {
rangeEnd = char32;
continue;
}
if (lastCat >= 0) {
if (catStrings[lastCat].length() > lastNewline[lastCat] + 70) {
lastNewline[lastCat] = catStrings[lastCat].length() + 10;
String[] arrstring = catStrings;
int n2 = lastCat;
arrstring[n2] = arrstring[n2] + "\n ";
}
String[] arrstring = catStrings;
int n3 = lastCat;
arrstring[n3] = arrstring[n3] + " " + Integer.toHexString(rangeStart);
if (rangeEnd != rangeStart) {
String[] arrstring2 = catStrings;
int n4 = lastCat;
arrstring2[n4] = arrstring2[n4] + "-" + Integer.toHexString(rangeEnd);
}
}
lastCat = category;
rangeStart = rangeEnd = char32;
}
String[] arrstring = catStrings;
int n5 = lastCat;
arrstring[n5] = arrstring[n5] + " " + Integer.toHexString(rangeStart);
if (rangeEnd != rangeStart) {
String[] arrstring3 = catStrings;
int n6 = lastCat;
arrstring3[n6] = arrstring3[n6] + "-" + Integer.toHexString(rangeEnd);
}
for (category = 0; category <= this.fHeader.fCatCount; ++category) {
System.out.println(RBBIDataWrapper.intToString(category, 5) + " " + catStrings[category]);
}
System.out.println();
}
static class TrieFoldingFunc
implements Trie.DataManipulate {
TrieFoldingFunc() {
}
public int getFoldingOffset(int data) {
if ((data & 32768) != 0) {
return data & 32767;
}
return 0;
}
}
static final class RBBIDataHeader {
int fMagic = 0;
int fVersion;
byte[] fFormatVersion = new byte[4];
int fLength;
int fCatCount;
int fFTable;
int fFTableLen;
int fRTable;
int fRTableLen;
int fSFTable;
int fSFTableLen;
int fSRTable;
int fSRTableLen;
int fTrie;
int fTrieLen;
int fRuleSource;
int fRuleSourceLen;
int fStatusTable;
int fStatusTableLen;
}
}