1 | private int matchString (Context con, Op op, int offset, int dx, int opts) {↵ | | 1 | private int matchCharacterIterator (Context con, Op op, int offset, int dx, int opts) {↵
|
|
|
|
|
2 | String target = con.strTarget;↵ | | 2 | CharacterIterator target = con.ciTarget;↵
|
|
|
|
|
|
|
3 | while (true) {↵ | | 3 | while (true) {↵
|
4 | if (op == null)↵ | | 4 | if (op == null)↵
|
5 | return isSet(opts, XMLSCHEMA_MODE) && offset != con.limit ? -1 : offset;↵ | | 5 | return isSet(opts, XMLSCHEMA_MODE) && offset != con.limit ? -1 : offset;↵
|
6 | if (offset > con.limit || offset < con.start)↵ | | 6 | if (offset > con.limit || offset < con.start)↵
|
7 | return -1;↵ | | 7 | return -1;↵
|
8 | switch (op.type) {↵ | | 8 | switch (op.type) {↵
|
9 | case Op.CHAR:↵ | | 9 | case Op.CHAR:↵
|
10 | if (isSet(opts, IGNORE_CASE)) {↵ | | 10 | if (isSet(opts, IGNORE_CASE)) {↵
|
11 | int ch = op.getData();↵ | | 11 | int ch = op.getData();↵
|
12 | if (dx > 0) {↵ | | 12 | if (dx > 0) {↵
|
13 | if (offset >= con.limit || !matchIgnoreCase(ch, target .charAt( offset ) ))↵ | | 13 | if (offset >= con.limit || !matchIgnoreCase(ch, target .setIndex( offset ) ))↵
|
14 | return -1;↵ | | 14 | return -1;↵
|
15 | offset ++;↵ | | 15 | offset ++;↵
|
16 | } else {↵ | | 16 | } else {↵
|
17 | int o1 = offset-1;↵ | | 17 | int o1 = offset-1;↵
|
18 | if (o1 >= con.limit || o1 < 0 || !matchIgnoreCase(ch, target .charAt( o1 ) ))↵ | | 18 | if (o1 >= con.limit || o1 < 0 || !matchIgnoreCase(ch, target .setIndex( o1 ) ))↵
|
19 | return -1;↵ | | 19 | return -1;↵
|
20 | offset = o1;↵ | | 20 | offset = o1;↵
|
21 | }↵ | | 21 | }↵
|
22 | } else {↵ | | 22 | } else {↵
|
23 | int ch = op.getData();↵ | | 23 | int ch = op.getData();↵
|
24 | if (dx > 0) {↵ | | 24 | if (dx > 0) {↵
|
25 | if (offset >= con.limit || ch != target .charAt( offset ) )↵ | | 25 | if (offset >= con.limit || ch != target .setIndex( offset ) )↵
|
26 | return -1;↵ | | 26 | return -1;↵
|
27 | offset ++;↵ | | 27 | offset ++;↵
|
28 | } else {↵ | | 28 | } else {↵
|
29 | int o1 = offset-1;↵ | | 29 | int o1 = offset-1;↵
|
30 | if (o1 >= con.limit || o1 < 0 || ch != target .charAt( o1 ) )↵ | | 30 | if (o1 >= con.limit || o1 < 0 || ch != target .setIndex( o1 ) )↵
|
31 | return -1;↵ | | 31 | return -1;↵
|
32 | offset = o1;↵ | | 32 | offset = o1;↵
|
33 | }↵ | | 33 | }↵
|
34 | }↵ | | 34 | }↵
|
35 | op = op.next;↵ | | 35 | op = op.next;↵
|
36 | break;↵ | | 36 | break;↵
|
|
37 | case Op.DOT:↵ | | 37 | case Op.DOT:↵
|
38 | if (dx > 0) {↵ | | 38 | if (dx > 0) {↵
|
39 | if (offset >= con.limit)↵ | | 39 | if (offset >= con.limit)↵
|
40 | return -1;↵ | | 40 | return -1;↵
|
41 | int ch = target .charAt( offset ) ;↵ | | 41 | int ch = target .setIndex( offset ) ;↵
|
42 | if (isSet(opts, SINGLE_LINE)) {↵ | | 42 | if (isSet(opts, SINGLE_LINE)) {↵
|
43 | if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)↵ | | 43 | if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)↵
|
44 | offset ++;↵ | | 44 | offset ++;↵
|
45 | } else {↵ | | 45 | } else {↵
|
46 | if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)↵ | | 46 | if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)↵
|
47 | ch = REUtil.composeFromSurrogates(ch, target .charAt( ++offset ) );↵ | | 47 | ch = REUtil.composeFromSurrogates(ch, target .setIndex( ++offset ) );↵
|
48 | if (isEOLChar(ch))↵ | | 48 | if (isEOLChar(ch))↵
|
49 | return -1;↵ | | 49 | return -1;↵
|
50 | }↵ | | 50 | }↵
|
51 | offset ++;↵ | | 51 | offset ++;↵
|
52 | } else {↵ | | 52 | } else {↵
|
53 | int o1 = offset-1;↵ | | 53 | int o1 = offset-1;↵
|
54 | if (o1 >= con.limit || o1 < 0)↵ | | 54 | if (o1 >= con.limit || o1 < 0)↵
|
55 | return -1;↵ | | 55 | return -1;↵
|
56 | int ch = target .charAt( o1 ) ;↵ | | 56 | int ch = target .setIndex( o1 ) ;↵
|
57 | if (isSet(opts, SINGLE_LINE)) {↵ | | 57 | if (isSet(opts, SINGLE_LINE)) {↵
|
58 | if (REUtil.isLowSurrogate(ch) && o1-1 >= 0)↵ | | 58 | if (REUtil.isLowSurrogate(ch) && o1-1 >= 0)↵
|
59 | o1 --;↵ | | 59 | o1 --;↵
|
60 | } else {↵ | | 60 | } else {↵
|
61 | if (REUtil.isLowSurrogate(ch) && o1-1 >= 0)↵ | | 61 | if (REUtil.isLowSurrogate(ch) && o1-1 >= 0)↵
|
62 | ch = REUtil.composeFromSurrogates( target .charAt( --o1 ) , ch);↵ | | 62 | ch = REUtil.composeFromSurrogates( target .setIndex( --o1 ) , ch);↵
|
63 | if (!isEOLChar(ch))↵ | | 63 | if (!isEOLChar(ch))↵
|
64 | return -1;↵ | | 64 | return -1;↵
|
65 | }↵ | | 65 | }↵
|
66 | offset = o1;↵ | | 66 | offset = o1;↵
|
67 | }↵ | | 67 | }↵
|
68 | op = op.next;↵ | | 68 | op = op.next;↵
|
69 | break;↵ | | 69 | break;↵
|
|
70 | case Op.RANGE:↵ | | 70 | case Op.RANGE:↵
|
71 | case Op.NRANGE:↵ | | 71 | case Op.NRANGE:↵
|
72 | if (dx > 0) {↵ | | 72 | if (dx > 0) {↵
|
73 | if (offset >= con.limit)↵ | | 73 | if (offset >= con.limit)↵
|
74 | return -1;↵ | | 74 | return -1;↵
|
75 | int ch = target .charAt( offset ) ;↵ | | 75 | int ch = target .setIndex( offset ) ;↵
|
76 | if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)↵ | | 76 | if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)↵
|
77 | ch = REUtil.composeFromSurrogates(ch, target .charAt( ++offset ) );↵ | | 77 | ch = REUtil.composeFromSurrogates(ch, target .setIndex( ++offset ) );↵
|
78 | RangeToken tok = op.getToken();↵ | | 78 | RangeToken tok = op.getToken();↵
|
79 | if (isSet(opts, IGNORE_CASE)) {↵ | | 79 | if (isSet(opts, IGNORE_CASE)) {↵
|
80 | tok = tok.getCaseInsensitiveToken();↵ | | 80 | tok = tok.getCaseInsensitiveToken();↵
|
81 | if (!tok.match(ch)) {↵ | | 81 | if (!tok.match(ch)) {↵
|
82 | if (ch >= 0x10000) return -1;↵ | | 82 | if (ch >= 0x10000) return -1;↵
|
83 | char uch;↵ | | 83 | char uch;↵
|
84 | if (!tok.match(uch = Character.toUpperCase((char)ch))↵ | | 84 | if (!tok.match(uch = Character.toUpperCase((char)ch))↵
|
85 | && !tok.match(Character.toLowerCase(uch)))↵ | | 85 | && !tok.match(Character.toLowerCase(uch)))↵
|
86 | return -1;↵ | | 86 | return -1;↵
|
87 | }↵ | | 87 | }↵
|
88 | } else {↵ | | 88 | } else {↵
|
89 | if (!tok.match(ch)) return -1;↵ | | 89 | if (!tok.match(ch)) return -1;↵
|
90 | }↵ | | 90 | }↵
|
91 | offset ++;↵ | | 91 | offset ++;↵
|
92 | } else {↵ | | 92 | } else {↵
|
93 | int o1 = offset-1;↵ | | 93 | int o1 = offset-1;↵
|
94 | if (o1 >= con.limit || o1 < 0)↵ | | 94 | if (o1 >= con.limit || o1 < 0)↵
|
95 | return -1;↵ | | 95 | return -1;↵
|
96 | int ch = target .charAt( o1 ) ;↵ | | 96 | int ch = target .setIndex( o1 ) ;↵
|
97 | if (REUtil.isLowSurrogate(ch) && o1-1 >= 0)↵ | | 97 | if (REUtil.isLowSurrogate(ch) && o1-1 >= 0)↵
|
98 | ch = REUtil.composeFromSurrogates( target .charAt( --o1 ) , ch);↵ | | 98 | ch = REUtil.composeFromSurrogates( target .setIndex( --o1 ) , ch);↵
|
99 | RangeToken tok = op.getToken();↵ | | 99 | RangeToken tok = op.getToken();↵
|
100 | if (isSet(opts, IGNORE_CASE)) {↵ | | 100 | if (isSet(opts, IGNORE_CASE)) {↵
|
101 | tok = tok.getCaseInsensitiveToken();↵ | | 101 | tok = tok.getCaseInsensitiveToken();↵
|
102 | if (!tok.match(ch)) {↵ | | 102 | if (!tok.match(ch)) {↵
|
103 | if (ch >= 0x10000) return -1;↵ | | 103 | if (ch >= 0x10000) return -1;↵
|
104 | char uch;↵ | | 104 | char uch;↵
|
105 | if (!tok.match(uch = Character.toUpperCase((char)ch))↵ | | 105 | if (!tok.match(uch = Character.toUpperCase((char)ch))↵
|
106 | && !tok.match(Character.toLowerCase(uch)))↵ | | 106 | && !tok.match(Character.toLowerCase(uch)))↵
|
107 | return -1;↵ | | 107 | return -1;↵
|
108 | }↵ | | 108 | }↵
|
109 | } else {↵ | | 109 | } else {↵
|
110 | if (!tok.match(ch)) return -1;↵ | | 110 | if (!tok.match(ch)) return -1;↵
|
111 | }↵ | | 111 | }↵
|
112 | offset = o1;↵ | | 112 | offset = o1;↵
|
113 | }↵ | | 113 | }↵
|
114 | op = op.next;↵ | | 114 | op = op.next;↵
|
115 | break;↵ | | 115 | break;↵
|
|
116 | case Op.ANCHOR:↵ | | 116 | case Op.ANCHOR:↵
|
117 | boolean go = false;↵ | | 117 | boolean go = false;↵
|
118 | switch (op.getData()) {↵ | | 118 | switch (op.getData()) {↵
|
119 | case '^':↵ | | 119 | case '^':↵
|
120 | if (isSet(opts, MULTIPLE_LINES)) {↵ | | 120 | if (isSet(opts, MULTIPLE_LINES)) {↵
|
121 | if (!(offset == con.start↵ | | 121 | if (!(offset == con.start↵
|
122 | || offset > con.start && isEOLChar( target .charAt( offset-1 ) )))↵ | | 122 | || offset > con.start && isEOLChar( target .setIndex( offset-1 ) )))↵
|
123 | return -1;↵ | | 123 | return -1;↵
|
124 | } else {↵ | | 124 | } else {↵
|
125 | if (offset != con.start)↵ | | 125 | if (offset != con.start)↵
|
126 | return -1;↵ | | 126 | return -1;↵
|
127 | }↵ | | 127 | }↵
|
128 | break;↵ | | 128 | break;↵
|
|
129 | case '@': // Internal use only.↵ | | 129 | case '@': // Internal use only.↵
|
130 | // The @ always matches line beginnings.↵ | | 130 | // The @ always matches line beginnings.↵
|
131 | if (!(offset == con.start↵ | | 131 | if (!(offset == con.start↵
|
132 | || offset > con.start && isEOLChar( target .charAt( offset-1 ) )))↵ | | 132 | || offset > con.start && isEOLChar( target .setIndex( offset-1 ) )))↵
|
133 | return -1;↵ | | 133 | return -1;↵
|
134 | break;↵ | | 134 | break;↵
|
|
135 | case '$':↵ | | 135 | case '$':↵
|
136 | if (isSet(opts, MULTIPLE_LINES)) {↵ | | 136 | if (isSet(opts, MULTIPLE_LINES)) {↵
|
137 | if (!(offset == con.limit↵ | | 137 | if (!(offset == con.limit↵
|
138 | || offset < con.limit && isEOLChar( target .charAt( offset ) )))↵ | | 138 | || offset < con.limit && isEOLChar( target .setIndex( offset ) )))↵
|
139 | return -1;↵ | | 139 | return -1;↵
|
140 | } else {↵ | | 140 | } else {↵
|
141 | if (!(offset == con.limit↵ | | 141 | if (!(offset == con.limit↵
|
142 | || offset+1 == con.limit && isEOLChar( target .charAt( offset ) )↵ | | 142 | || offset+1 == con.limit && isEOLChar( target .setIndex( offset ) )↵
|
143 | || offset+2 == con.limit && target .charAt( offset ) == CARRIAGE_RETURN↵ | | 143 | || offset+2 == con.limit && target .setIndex( offset ) == CARRIAGE_RETURN↵
|
144 | && target .charAt( offset+1 ) == LINE_FEED))↵ | | 144 | && target .setIndex( offset+1 ) == LINE_FEED))↵
|
145 | return -1;↵ | | 145 | return -1;↵
|
146 | }↵ | | 146 | }↵
|
147 | break;↵ | | 147 | break;↵
|
|
148 | case 'A':↵ | | 148 | case 'A':↵
|
149 | if (offset != con.start) return -1;↵ | | 149 | if (offset != con.start) return -1;↵
|
150 | break;↵ | | 150 | break;↵
|
|
151 | case 'Z':↵ | | 151 | case 'Z':↵
|
152 | if (!(offset == con.limit↵ | | 152 | if (!(offset == con.limit↵
|
153 | || offset+1 == con.limit && isEOLChar( target .charAt( offset ) )↵ | | 153 | || offset+1 == con.limit && isEOLChar( target .setIndex( offset ) )↵
|
154 | || offset+2 == con.limit && target .charAt( offset ) == CARRIAGE_RETURN↵ | | 154 | || offset+2 == con.limit && target .setIndex( offset ) == CARRIAGE_RETURN↵
|
155 | && target .charAt( offset+1 ) == LINE_FEED))↵ | | 155 | && target .setIndex( offset+1 ) == LINE_FEED))↵
|
156 | return -1;↵ | | 156 | return -1;↵
|
157 | break;↵ | | 157 | break;↵
|
|
158 | case 'z':↵ | | 158 | case 'z':↵
|
159 | if (offset != con.limit) return -1;↵ | | 159 | if (offset != con.limit) return -1;↵
|
160 | break;↵ | | 160 | break;↵
|
|
161 | case 'b':↵ | | 161 | case 'b':↵
|
162 | if (con.length == 0) return -1;↵ | | 162 | if (con.length == 0) return -1;↵
|
163 | {↵ | | 163 | {↵
|
164 | int after = getWordType(target, con.start, con.limit, offset, opts);↵ | | 164 | int after = getWordType(target, con.start, con.limit, offset, opts);↵
|
165 | if (after == WT_IGNORE) return -1;↵ | | 165 | if (after == WT_IGNORE) return -1;↵
|
166 | int before = getPreviousWordType(target, con.start, con.limit, offset, opts);↵ | | 166 | int before = getPreviousWordType(target, con.start, con.limit, offset, opts);↵
|
167 | if (after == before) return -1;↵ | | 167 | if (after == before) return -1;↵
|
168 | }↵ | | 168 | }↵
|
169 | break;↵ | | 169 | break;↵
|
|
170 | case 'B':↵ | | 170 | case 'B':↵
|
171 | if (con.length == 0)↵ | | 171 | if (con.length == 0)↵
|
172 | go = true;↵ | | 172 | go = true;↵
|
173 | else {↵ | | 173 | else {↵
|
174 | int after = getWordType(target, con.start, con.limit, offset, opts);↵ | | 174 | int after = getWordType(target, con.start, con.limit, offset, opts);↵
|
175 | go = after == WT_IGNORE↵ | | 175 | go = after == WT_IGNORE↵
|
176 | || after == getPreviousWordType(target, con.start, con.limit, offset, opts);↵ | | 176 | || after == getPreviousWordType(target, con.start, con.limit, offset, opts);↵
|
177 | }↵ | | 177 | }↵
|
178 | if (!go) return -1;↵ | | 178 | if (!go) return -1;↵
|
179 | break;↵ | | 179 | break;↵
|
|
180 | case '<':↵ | | 180 | case '<':↵
|
181 | if (con.length == 0 || offset == con.limit) return -1;↵ | | 181 | if (con.length == 0 || offset == con.limit) return -1;↵
|
182 | if (getWordType(target, con.start, con.limit, offset, opts) != WT_LETTER↵ | | 182 | if (getWordType(target, con.start, con.limit, offset, opts) != WT_LETTER↵
|
183 | || getPreviousWordType(target, con.start, con.limit, offset, opts) != WT_OTHER)↵ | | 183 | || getPreviousWordType(target, con.start, con.limit, offset, opts) != WT_OTHER)↵
|
184 | return -1;↵ | | 184 | return -1;↵
|
185 | break;↵ | | 185 | break;↵
|
|
186 | case '>':↵ | | 186 | case '>':↵
|
187 | if (con.length == 0 || offset == con.start) return -1;↵ | | 187 | if (con.length == 0 || offset == con.start) return -1;↵
|
188 | if (getWordType(target, con.start, con.limit, offset, opts) != WT_OTHER↵ | | 188 | if (getWordType(target, con.start, con.limit, offset, opts) != WT_OTHER↵
|
189 | || getPreviousWordType(target, con.start, con.limit, offset, opts) != WT_LETTER)↵ | | 189 | || getPreviousWordType(target, con.start, con.limit, offset, opts) != WT_LETTER)↵
|
190 | return -1;↵ | | 190 | return -1;↵
|
191 | break;↵ | | 191 | break;↵
|
192 | } // switch anchor type↵ | | 192 | } // switch anchor type↵
|
193 | op = op.next;↵ | | 193 | op = op.next;↵
|
194 | break;↵ | | 194 | break;↵
|
|
195 | case Op.BACKREFERENCE:↵ | | 195 | case Op.BACKREFERENCE:↵
|
196 | {↵ | | 196 | {↵
|
197 | int refno = op.getData();↵ | | 197 | int refno = op.getData();↵
|
198 | if (refno <= 0 || refno >= this.nofparen)↵ | | 198 | if (refno <= 0 || refno >= this.nofparen)↵
|
199 | throw new RuntimeException("Internal Error: Reference number must be more than zero: "+refno);↵ | | 199 | throw new RuntimeException("Internal Error: Reference number must be more than zero: "+refno);↵
|
200 | if (con.match.getBeginning(refno) < 0↵ | | 200 | if (con.match.getBeginning(refno) < 0↵
|
201 | || con.match.getEnd(refno) < 0)↵ | | 201 | || con.match.getEnd(refno) < 0)↵
|
202 | return -1; // ********↵ | | 202 | return -1; // ********↵
|
203 | int o2 = con.match.getBeginning(refno);↵ | | 203 | int o2 = con.match.getBeginning(refno);↵
|
204 | int literallen = con.match.getEnd(refno)-o2;↵ | | 204 | int literallen = con.match.getEnd(refno)-o2;↵
|
205 | if (!isSet(opts, IGNORE_CASE)) {↵ | | 205 | if (!isSet(opts, IGNORE_CASE)) {↵
|
206 | if (dx > 0) {↵ | | 206 | if (dx > 0) {↵
|
207 | if (!regionMatches(target, offset, con.limit, o2, literallen))↵ | | 207 | if (!regionMatches(target, offset, con.limit, o2, literallen))↵
|
208 | return -1;↵ | | 208 | return -1;↵
|
209 | offset += literallen;↵ | | 209 | offset += literallen;↵
|
210 | } else {↵ | | 210 | } else {↵
|
211 | if (!regionMatches(target, offset-literallen, con.limit, o2, literallen))↵ | | 211 | if (!regionMatches(target, offset-literallen, con.limit, o2, literallen))↵
|
212 | return -1;↵ | | 212 | return -1;↵
|
213 | offset -= literallen;↵ | | 213 | offset -= literallen;↵
|
214 | }↵ | | 214 | }↵
|
215 | } else {↵ | | 215 | } else {↵
|
216 | if (dx > 0) {↵ | | 216 | if (dx > 0) {↵
|
217 | if (!regionMatchesIgnoreCase(target, offset, con.limit, o2, literallen))↵ | | 217 | if (!regionMatchesIgnoreCase(target, offset, con.limit, o2, literallen))↵
|
218 | return -1;↵ | | 218 | return -1;↵
|
219 | offset += literallen;↵ | | 219 | offset += literallen;↵
|
220 | } else {↵ | | 220 | } else {↵
|
221 | if (!regionMatchesIgnoreCase(target, offset-literallen, con.limit,↵ | | 221 | if (!regionMatchesIgnoreCase(target, offset-literallen, con.limit,↵
|
222 | o2, literallen))↵ | | 222 | o2, literallen))↵
|
223 | return -1;↵ | | 223 | return -1;↵
|
224 | offset -= literallen;↵ | | 224 | offset -= literallen;↵
|
225 | }↵ | | 225 | }↵
|
226 | }↵ | | 226 | }↵
|
227 | }↵ | | 227 | }↵
|
228 | op = op.next;↵ | | 228 | op = op.next;↵
|
229 | break;↵ | | 229 | break;↵
|
230 | case Op.STRING:↵ | | 230 | case Op.STRING:↵
|
231 | {↵ | | 231 | {↵
|
232 | String literal = op.getString();↵ | | 232 | String literal = op.getString();↵
|
233 | int literallen = literal.length();↵ | | 233 | int literallen = literal.length();↵
|
234 | if (!isSet(opts, IGNORE_CASE)) {↵ | | 234 | if (!isSet(opts, IGNORE_CASE)) {↵
|
235 | if (dx > 0) {↵ | | 235 | if (dx > 0) {↵
|
236 | if (!regionMatches(target, offset, con.limit, literal, literallen))↵ | | 236 | if (!regionMatches(target, offset, con.limit, literal, literallen))↵
|
237 | return -1;↵ | | 237 | return -1;↵
|
238 | offset += literallen;↵ | | 238 | offset += literallen;↵
|
239 | } else {↵ | | 239 | } else {↵
|
240 | if (!regionMatches(target, offset-literallen, con.limit, literal, literallen))↵ | | 240 | if (!regionMatches(target, offset-literallen, con.limit, literal, literallen))↵
|
241 | return -1;↵ | | 241 | return -1;↵
|
242 | offset -= literallen;↵ | | 242 | offset -= literallen;↵
|
243 | }↵ | | 243 | }↵
|
244 | } else {↵ | | 244 | } else {↵
|
245 | if (dx > 0) {↵ | | 245 | if (dx > 0) {↵
|
246 | if (!regionMatchesIgnoreCase(target, offset, con.limit, literal, literallen))↵ | | 246 | if (!regionMatchesIgnoreCase(target, offset, con.limit, literal, literallen))↵
|
247 | return -1;↵ | | 247 | return -1;↵
|
248 | offset += literallen;↵ | | 248 | offset += literallen;↵
|
249 | } else {↵ | | 249 | } else {↵
|
250 | if (!regionMatchesIgnoreCase(target, offset-literallen, con.limit,↵ | | 250 | if (!regionMatchesIgnoreCase(target, offset-literallen, con.limit,↵
|
251 | literal, literallen))↵ | | 251 | literal, literallen))↵
|
252 | return -1;↵ | | 252 | return -1;↵
|
253 | offset -= literallen;↵ | | 253 | offset -= literallen;↵
|
254 | }↵ | | 254 | }↵
|
255 | }↵ | | 255 | }↵
|
256 | }↵ | | 256 | }↵
|
257 | op = op.next;↵ | | 257 | op = op.next;↵
|
258 | break;↵ | | 258 | break;↵
|
|
259 | case Op.CLOSURE:↵ | | 259 | case Op.CLOSURE:↵
|
260 | {↵ | | 260 | {↵
|
261 | /*↵ | | 261 | /*↵
|
262 | * Saves current position to avoid↵ | | 262 | * Saves current position to avoid↵
|
263 | * zero-width repeats.↵ | | 263 | * zero-width repeats.↵
|
264 | */↵ | | 264 | */↵
|
265 | int id = op.getData();↵ | | 265 | int id = op.getData();↵
|
266 | if (id >= 0) {↵ | | 266 | if (id >= 0) {↵
|
267 | int previousOffset = con.offsets[id];↵ | | 267 | int previousOffset = con.offsets[id];↵
|
268 | if (previousOffset < 0 || previousOffset != offset) {↵ | | 268 | if (previousOffset < 0 || previousOffset != offset) {↵
|
269 | con.offsets[id] = offset;↵ | | 269 | con.offsets[id] = offset;↵
|
270 | } else {↵ | | 270 | } else {↵
|
271 | con.offsets[id] = -1;↵ | | 271 | con.offsets[id] = -1;↵
|
272 | op = op.next;↵ | | 272 | op = op.next;↵
|
273 | break;↵ | | 273 | break;↵
|
274 | }↵ | | 274 | }↵
|
275 | }↵ | | 275 | }↵
|
| | | 276 | ↵
|
276 | int ret = this. matchString (con, op.getChild(), offset, dx, opts);↵ | | 277 | int ret = this. matchCharacterIterator (con, op.getChild(), offset, dx, opts);↵
|
277 | if (id >= 0) con.offsets[id] = -1;↵ | | 278 | if (id >= 0) con.offsets[id] = -1;↵
|
278 | if (ret >= 0) return ret;↵ | | 279 | if (ret >= 0) return ret;↵
|
279 | op = op.next;↵ | | 280 | op = op.next;↵
|
280 | }↵ | | 281 | }↵
|
281 | break;↵ | | 282 | break;↵
|
|
282 | case Op.QUESTION:↵ | | 283 | case Op.QUESTION:↵
|
283 | {↵ | | 284 | {↵
|
284 | int ret = this. matchString (con, op.getChild(), offset, dx, opts);↵ | | 285 | int ret = this. matchCharacterIterator (con, op.getChild(), offset, dx, opts);↵
|
285 | if (ret >= 0) return ret;↵ | | 286 | if (ret >= 0) return ret;↵
|
286 | op = op.next;↵ | | 287 | op = op.next;↵
|
287 | }↵ | | 288 | }↵
|
288 | break;↵ | | 289 | break;↵
|
|
289 | case Op.NONGREEDYCLOSURE:↵ | | 290 | case Op.NONGREEDYCLOSURE:↵
|
290 | case Op.NONGREEDYQUESTION:↵ | | 291 | case Op.NONGREEDYQUESTION:↵
|
291 | {↵ | | 292 | {↵
|
292 | int ret = this. matchString (con, op.next, offset, dx, opts);↵ | | 293 | int ret = this. matchCharacterIterator (con, op.next, offset, dx, opts);↵
|
293 | if (ret >= 0) return ret;↵ | | 294 | if (ret >= 0) return ret;↵
|
294 | op = op.getChild();↵ | | 295 | op = op.getChild();↵
|
295 | }↵ | | 296 | }↵
|
296 | break;↵ | | 297 | break;↵
|
|
297 | case Op.UNION:↵ | | 298 | case Op.UNION:↵
|
298 | for (int i = 0; i < op.size(); i ++) {↵ | | 299 | for (int i = 0; i < op.size(); i ++) {↵
|
299 | int ret = this. matchString (con, op.elementAt(i), offset, dx, opts);↵ | | 300 | int ret = this. matchCharacterIterator (con, op.elementAt(i), offset, dx, opts);↵
|
300 | if (DEBUG) {↵ | | 301 | if (DEBUG) {↵
|
301 | System.err.println("UNION: "+i+", ret="+ret);↵ | | 302 | System.err.println("UNION: "+i+", ret="+ret);↵
|
302 | }↵ | | 303 | }↵
|
303 | if (ret >= 0) return ret;↵ | | 304 | if (ret >= 0) return ret;↵
|
304 | }↵ | | 305 | }↵
|
305 | return -1;↵ | | 306 | return -1;↵
|
|
306 | case Op.CAPTURE:↵ | | 307 | case Op.CAPTURE:↵
|
307 | int refno = op.getData();↵ | | 308 | int refno = op.getData();↵
|
308 | if (con.match != null && refno > 0) {↵ | | 309 | if (con.match != null && refno > 0) {↵
|
309 | int save = con.match.getBeginning(refno);↵ | | 310 | int save = con.match.getBeginning(refno);↵
|
310 | con.match.setBeginning(refno, offset);↵ | | 311 | con.match.setBeginning(refno, offset);↵
|
311 | int ret = this. matchString (con, op.next, offset, dx, opts);↵ | | 312 | int ret = this. matchCharacterIterator (con, op.next, offset, dx, opts);↵
|
312 | if (ret < 0) con.match.setBeginning(refno, save);↵ | | 313 | if (ret < 0) con.match.setBeginning(refno, save);↵
|
313 | return ret;↵ | | 314 | return ret;↵
|
314 | } else if (con.match != null && refno < 0) {↵ | | 315 | } else if (con.match != null && refno < 0) {↵
|
315 | int index = -refno;↵ | | 316 | int index = -refno;↵
|
316 | int save = con.match.getEnd(index);↵ | | 317 | int save = con.match.getEnd(index);↵
|
317 | con.match.setEnd(index, offset);↵ | | 318 | con.match.setEnd(index, offset);↵
|
318 | int ret = this. matchString (con, op.next, offset, dx, opts);↵ | | 319 | int ret = this. matchCharacterIterator (con, op.next, offset, dx, opts);↵
|
319 | if (ret < 0) con.match.setEnd(index, save);↵ | | 320 | if (ret < 0) con.match.setEnd(index, save);↵
|
320 | return ret;↵ | | 321 | return ret;↵
|
321 | }↵ | | 322 | }↵
|
322 | op = op.next;↵ | | 323 | op = op.next;↵
|
323 | break;↵ | | 324 | break;↵
|
|
324 | case Op.LOOKAHEAD:↵ | | 325 | case Op.LOOKAHEAD:↵
|
325 | if (0 > this. matchString (con, op.getChild(), offset, 1, opts)) return -1;↵ | | 326 | if (0 > this. matchCharacterIterator (con, op.getChild(), offset, 1, opts)) return -1;↵
|
326 | op = op.next;↵ | | 327 | op = op.next;↵
|
327 | break;↵ | | 328 | break;↵
|
328 | case Op.NEGATIVELOOKAHEAD:↵ | | 329 | case Op.NEGATIVELOOKAHEAD:↵
|
329 | if (0 <= this. matchString (con, op.getChild(), offset, 1, opts)) return -1;↵ | | 330 | if (0 <= this. matchCharacterIterator (con, op.getChild(), offset, 1, opts)) return -1;↵
|
330 | op = op.next;↵ | | 331 | op = op.next;↵
|
331 | break;↵ | | 332 | break;↵
|
332 | case Op.LOOKBEHIND:↵ | | 333 | case Op.LOOKBEHIND:↵
|
333 | if (0 > this. matchString (con, op.getChild(), offset, -1, opts)) return -1;↵ | | 334 | if (0 > this. matchCharacterIterator (con, op.getChild(), offset, -1, opts)) return -1;↵
|
334 | op = op.next;↵ | | 335 | op = op.next;↵
|
335 | break;↵ | | 336 | break;↵
|
336 | case Op.NEGATIVELOOKBEHIND:↵ | | 337 | case Op.NEGATIVELOOKBEHIND:↵
|
337 | if (0 <= this. matchString (con, op.getChild(), offset, -1, opts)) return -1;↵ | | 338 | if (0 <= this. matchCharacterIterator (con, op.getChild(), offset, -1, opts)) return -1;↵
|
338 | op = op.next;↵ | | 339 | op = op.next;↵
|
339 | break;↵ | | 340 | break;↵
|
|
340 | case Op.INDEPENDENT:↵ | | 341 | case Op.INDEPENDENT:↵
|
341 | {↵ | | 342 | {↵
|
342 | int ret = this. matchString (con, op.getChild(), offset, dx, opts);↵ | | 343 | int ret = this. matchCharacterIterator (con, op.getChild(), offset, dx, opts);↵
|
343 | if (ret < 0) return ret;↵ | | 344 | if (ret < 0) return ret;↵
|
344 | offset = ret;↵ | | 345 | offset = ret;↵
|
345 | op = op.next;↵ | | 346 | op = op.next;↵
|
346 | }↵ | | 347 | }↵
|
347 | break;↵ | | 348 | break;↵
|
|
348 | case Op.MODIFIER:↵ | | 349 | case Op.MODIFIER:↵
|
349 | {↵ | | 350 | {↵
|
350 | int localopts = opts;↵ | | 351 | int localopts = opts;↵
|
351 | localopts |= op.getData();↵ | | 352 | localopts |= op.getData();↵
|
352 | localopts &= ~op.getData2();↵ | | 353 | localopts &= ~op.getData2();↵
|
353 | //System.err.println("MODIFIER: "+Integer.toString(opts, 16)+" -> "+Integer.toString(localopts, 16));↵ | | 354 | //System.err.println("MODIFIER: "+Integer.toString(opts, 16)+" -> "+Integer.toString(localopts, 16));↵
|
354 | int ret = this. matchString (con, op.getChild(), offset, dx, localopts);↵ | | 355 | int ret = this. matchCharacterIterator (con, op.getChild(), offset, dx, localopts);↵
|
355 | if (ret < 0) return ret;↵ | | 356 | if (ret < 0) return ret;↵
|
356 | offset = ret;↵ | | 357 | offset = ret;↵
|
357 | op = op.next;↵ | | 358 | op = op.next;↵
|
358 | }↵ | | 359 | }↵
|
359 | break;↵ | | 360 | break;↵
|
|
360 | case Op.CONDITION:↵ | | 361 | case Op.CONDITION:↵
|
361 | {↵ | | 362 | {↵
|
362 | Op.ConditionOp cop = (Op.ConditionOp)op;↵ | | 363 | Op.ConditionOp cop = (Op.ConditionOp)op;↵
|
363 | boolean matchp = false;↵ | | 364 | boolean matchp = false;↵
|
364 | if (cop.refNumber > 0) {↵ | | 365 | if (cop.refNumber > 0) {↵
|
365 | if (cop.refNumber >= this.nofparen)↵ | | 366 | if (cop.refNumber >= this.nofparen)↵
|
366 | throw new RuntimeException("Internal Error: Reference number must be more than zero: "+cop.refNumber);↵ | | 367 | throw new RuntimeException("Internal Error: Reference number must be more than zero: "+cop.refNumber);↵
|
367 | matchp = con.match.getBeginning(cop.refNumber) >= 0↵ | | 368 | matchp = con.match.getBeginning(cop.refNumber) >= 0↵
|
368 | && con.match.getEnd(cop.refNumber) >= 0;↵ | | 369 | && con.match.getEnd(cop.refNumber) >= 0;↵
|
369 | } else {↵ | | 370 | } else {↵
|
370 | matchp = 0 <= this. matchString (con, cop.condition, offset, dx, opts);↵ | | 371 | matchp = 0 <= this. matchCharacterIterator (con, cop.condition, offset, dx, opts);↵
|
371 | }↵ | | 372 | }↵
|
|
372 | if (matchp) {↵ | | 373 | if (matchp) {↵
|
373 | op = cop.yes;↵ | | 374 | op = cop.yes;↵
|
374 | } else if (cop.no != null) {↵ | | 375 | } else if (cop.no != null) {↵
|
375 | op = cop.no;↵ | | 376 | op = cop.no;↵
|
376 | } else {↵ | | 377 | } else {↵
|
377 | op = cop.next;↵ | | 378 | op = cop.next;↵
|
378 | }↵ | | 379 | }↵
|
379 | }↵ | | 380 | }↵
|
380 | break;↵ | | 381 | break;↵
|
|
381 | default:↵ | | 382 | default:↵
|
382 | throw new RuntimeException("Unknown operation type: "+op.type);↵ | | 383 | throw new RuntimeException("Unknown operation type: "+op.type);↵
|
383 | | | 384 |
|