Trie.java
4.44 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.text.UTF16;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public abstract class Trie {
protected char[] m_index_;
protected DataManipulate m_dataManipulate_;
protected int m_dataOffset_;
protected int m_dataLength_;
private boolean m_isLatin1Linear_;
private int m_options_;
public final boolean isLatin1Linear() {
return this.m_isLatin1Linear_;
}
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof Trie)) {
return false;
}
Trie othertrie = (Trie)other;
return this.m_isLatin1Linear_ == othertrie.m_isLatin1Linear_ && this.m_options_ == othertrie.m_options_ && this.m_dataLength_ == othertrie.m_dataLength_ && Arrays.equals(this.m_index_, othertrie.m_index_);
}
public int getSerializedDataSize() {
int result = 16;
result += this.m_dataOffset_ << 1;
if (this.isCharTrie()) {
result += this.m_dataLength_ << 1;
} else if (this.isIntTrie()) {
result += this.m_dataLength_ << 2;
}
return result;
}
protected Trie(InputStream inputStream, DataManipulate dataManipulate) throws IOException {
DataInputStream input = new DataInputStream(inputStream);
int signature = input.readInt();
this.m_options_ = input.readInt();
if (!this.checkHeader(signature)) {
throw new IllegalArgumentException("ICU data file error: Trie header authentication failed, please check if you have the most updated ICU data file");
}
this.m_dataManipulate_ = dataManipulate != null ? dataManipulate : new DefaultGetFoldingOffset();
this.m_isLatin1Linear_ = (this.m_options_ & 512) != 0;
this.m_dataOffset_ = input.readInt();
this.m_dataLength_ = input.readInt();
this.unserialize(inputStream);
}
protected Trie(char[] index, int options, DataManipulate dataManipulate) {
this.m_options_ = options;
this.m_dataManipulate_ = dataManipulate != null ? dataManipulate : new DefaultGetFoldingOffset();
this.m_isLatin1Linear_ = (this.m_options_ & 512) != 0;
this.m_index_ = index;
this.m_dataOffset_ = this.m_index_.length;
}
protected abstract int getSurrogateOffset(char var1, char var2);
protected abstract int getValue(int var1);
protected abstract int getInitialValue();
protected final int getRawOffset(int offset, char ch) {
return (this.m_index_[offset + (ch >> 5)] << 2) + (ch & 31);
}
protected final int getBMPOffset(char ch) {
return ch >= '\ud800' && ch <= '\udbff' ? this.getRawOffset(320, ch) : this.getRawOffset(0, ch);
}
protected final int getLeadOffset(char ch) {
return this.getRawOffset(0, ch);
}
protected final int getCodePointOffset(int ch) {
if (ch < 0) {
return -1;
}
if (ch < 55296) {
return this.getRawOffset(0, (char)ch);
}
if (ch < 65536) {
return this.getBMPOffset((char)ch);
}
if (ch <= 1114111) {
return this.getSurrogateOffset(UTF16.getLeadSurrogate(ch), (char)(ch & 1023));
}
return -1;
}
protected void unserialize(InputStream inputStream) throws IOException {
this.m_index_ = new char[this.m_dataOffset_];
DataInputStream input = new DataInputStream(inputStream);
for (int i = 0; i < this.m_dataOffset_; ++i) {
this.m_index_[i] = input.readChar();
}
}
protected final boolean isIntTrie() {
return (this.m_options_ & 256) != 0;
}
protected final boolean isCharTrie() {
return (this.m_options_ & 256) == 0;
}
private final boolean checkHeader(int signature) {
if (signature != 1416784229) {
return false;
}
if ((this.m_options_ & 15) != 5 || (this.m_options_ >> 4 & 15) != 2) {
return false;
}
return true;
}
private static class DefaultGetFoldingOffset
implements DataManipulate {
private DefaultGetFoldingOffset() {
}
public int getFoldingOffset(int value) {
return value;
}
}
public static interface DataManipulate {
public int getFoldingOffset(int var1);
}
}