RuleCharacterIterator.java
4.88 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.impl.UCharacterProperty;
import com.adobe.agl.impl.Utility;
import com.adobe.agl.text.SymbolTable;
import com.adobe.agl.text.UTF16;
import java.text.ParsePosition;
public class RuleCharacterIterator {
private String text;
private ParsePosition pos;
private SymbolTable sym;
private char[] buf;
private int bufPos;
private boolean isEscaped;
public RuleCharacterIterator(String text, SymbolTable sym, ParsePosition pos) {
if (text == null || pos.getIndex() > text.length()) {
throw new IllegalArgumentException();
}
this.text = text;
this.sym = sym;
this.pos = pos;
this.buf = null;
}
public boolean atEnd() {
return this.buf == null && this.pos.getIndex() == this.text.length();
}
public int next(int options) {
int c;
block6 : {
c = -1;
this.isEscaped = false;
do {
c = this._current();
this._advance(UTF16.getCharCount(c));
if (c == 36 && this.buf == null && (options & 1) != 0 && this.sym != null) {
String name = this.sym.parseReference(this.text, this.pos, this.text.length());
if (name != null) {
this.bufPos = 0;
this.buf = this.sym.lookup(name);
if (this.buf == null) {
throw new IllegalArgumentException("Undefined variable: " + name);
}
if (this.buf.length != 0) continue;
this.buf = null;
continue;
}
break block6;
}
if ((options & 4) == 0 || !UCharacterProperty.isRuleWhiteSpace(c)) break;
} while (true);
if (c == 92 && (options & 2) != 0) {
int[] offset = new int[]{0};
c = Utility.unescapeAt(this.lookahead(), offset);
this.jumpahead(offset[0]);
this.isEscaped = true;
if (c < 0) {
throw new IllegalArgumentException("Invalid escape");
}
}
}
return c;
}
public boolean isEscaped() {
return this.isEscaped;
}
public boolean inVariable() {
return this.buf != null;
}
public Object getPos(Object p) {
if (p == null) {
return new Object[]{this.buf, new int[]{this.pos.getIndex(), this.bufPos}};
}
Object[] a = (Object[])p;
a[0] = this.buf;
int[] v = (int[])a[1];
v[0] = this.pos.getIndex();
v[1] = this.bufPos;
return p;
}
public void setPos(Object p) {
Object[] a = (Object[])p;
this.buf = (char[])a[0];
int[] v = (int[])a[1];
this.pos.setIndex(v[0]);
this.bufPos = v[1];
}
public void skipIgnored(int options) {
if ((options & 4) != 0) {
int a;
while (UCharacterProperty.isRuleWhiteSpace(a = this._current())) {
this._advance(UTF16.getCharCount(a));
}
}
}
public String lookahead() {
if (this.buf != null) {
return new String(this.buf, this.bufPos, this.buf.length - this.bufPos);
}
return this.text.substring(this.pos.getIndex());
}
public void jumpahead(int count) {
if (count < 0) {
throw new IllegalArgumentException();
}
if (this.buf != null) {
this.bufPos += count;
if (this.bufPos > this.buf.length) {
throw new IllegalArgumentException();
}
if (this.bufPos == this.buf.length) {
this.buf = null;
}
} else {
int i = this.pos.getIndex() + count;
this.pos.setIndex(i);
if (i > this.text.length()) {
throw new IllegalArgumentException();
}
}
}
public String toString() {
int b = this.pos.getIndex();
return this.text.substring(0, b) + '|' + this.text.substring(b);
}
private int _current() {
if (this.buf != null) {
return UTF16.charAt(this.buf, 0, this.buf.length, this.bufPos);
}
int i = this.pos.getIndex();
return i < this.text.length() ? UTF16.charAt(this.text, i) : -1;
}
private void _advance(int count) {
if (this.buf != null) {
this.bufPos += count;
if (this.bufPos == this.buf.length) {
this.buf = null;
}
} else {
this.pos.setIndex(this.pos.getIndex() + count);
if (this.pos.getIndex() > this.text.length()) {
this.pos.setIndex(this.text.length());
}
}
}
}