1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
package com.stevesoft.pat; |
9 |
|
|
10 |
|
import jalview.util.MessageManager; |
11 |
|
|
12 |
|
import java.io.File; |
13 |
|
import java.io.FilenameFilter; |
14 |
|
import java.util.BitSet; |
15 |
|
import java.util.Hashtable; |
16 |
|
|
17 |
|
import com.stevesoft.pat.wrap.StringWrap; |
18 |
|
|
19 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
20 |
|
class UnicodePunct extends UniValidator |
21 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
22 |
0 |
@Override... |
23 |
|
public int validate(StringLike s, int from, int to) |
24 |
|
{ |
25 |
0 |
return from < s.length() && Prop.isPunct(s.charAt(from)) ? to : -1; |
26 |
|
} |
27 |
|
} |
28 |
|
|
29 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
30 |
|
class UnicodeWhite extends UniValidator |
31 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
32 |
0 |
@Override... |
33 |
|
public int validate(StringLike s, int from, int to) |
34 |
|
{ |
35 |
0 |
return from < s.length() && Prop.isWhite(s.charAt(from)) ? to : -1; |
36 |
|
} |
37 |
|
} |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
42 |
|
class NUnicodePunct extends UniValidator |
43 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
44 |
0 |
@Override... |
45 |
|
public int validate(StringLike s, int from, int to) |
46 |
|
{ |
47 |
0 |
return from < s.length() && !Prop.isPunct(s.charAt(from)) ? to : -1; |
48 |
|
} |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
54 |
|
class NUnicodeWhite extends UniValidator |
55 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
56 |
0 |
@Override... |
57 |
|
public int validate(StringLike s, int from, int to) |
58 |
|
{ |
59 |
0 |
return from < s.length() && !Prop.isWhite(s.charAt(from)) ? to : -1; |
60 |
|
} |
61 |
|
} |
62 |
|
|
63 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1.25 |
|
64 |
|
class UnicodeW extends UniValidator |
65 |
|
{ |
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 5 |
Complexity Density: 1.25 |
|
66 |
0 |
@Override... |
67 |
|
public int validate(StringLike s, int from, int to) |
68 |
|
{ |
69 |
0 |
if (from >= s.length()) |
70 |
|
{ |
71 |
0 |
return -1; |
72 |
|
} |
73 |
0 |
char c = s.charAt(from); |
74 |
0 |
return (Prop.isAlphabetic(c) || Prop.isDecimalDigit(c) || c == '_') ? to |
75 |
|
: -1; |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1.25 |
|
80 |
|
class NUnicodeW extends UniValidator |
81 |
|
{ |
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 5 |
Complexity Density: 1.25 |
|
82 |
0 |
@Override... |
83 |
|
public int validate(StringLike s, int from, int to) |
84 |
|
{ |
85 |
0 |
if (from >= s.length()) |
86 |
|
{ |
87 |
0 |
return -1; |
88 |
|
} |
89 |
0 |
char c = s.charAt(from); |
90 |
0 |
return !(Prop.isAlphabetic(c) || Prop.isDecimalDigit(c) || c == '_') |
91 |
|
? to |
92 |
|
: -1; |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
97 |
|
class UnicodeDigit extends UniValidator |
98 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
99 |
0 |
@Override... |
100 |
|
public int validate(StringLike s, int from, int to) |
101 |
|
{ |
102 |
0 |
return from < s.length() && Prop.isDecimalDigit(s.charAt(from)) ? to |
103 |
|
: -1; |
104 |
|
} |
105 |
|
} |
106 |
|
|
107 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
108 |
|
class NUnicodeDigit extends UniValidator |
109 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
110 |
0 |
@Override... |
111 |
|
public int validate(StringLike s, int from, int to) |
112 |
|
{ |
113 |
0 |
return from < s.length() && !Prop.isDecimalDigit(s.charAt(from)) ? to |
114 |
|
: -1; |
115 |
|
} |
116 |
|
} |
117 |
|
|
118 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
119 |
|
class UnicodeMath extends UniValidator |
120 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
121 |
0 |
@Override... |
122 |
|
public int validate(StringLike s, int from, int to) |
123 |
|
{ |
124 |
0 |
return from < s.length() && Prop.isMath(s.charAt(from)) ? to : -1; |
125 |
|
} |
126 |
|
} |
127 |
|
|
128 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
129 |
|
class NUnicodeMath extends UniValidator |
130 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
131 |
0 |
@Override... |
132 |
|
public int validate(StringLike s, int from, int to) |
133 |
|
{ |
134 |
0 |
return from < s.length() && !Prop.isMath(s.charAt(from)) ? to : -1; |
135 |
|
} |
136 |
|
} |
137 |
|
|
138 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
139 |
|
class UnicodeCurrency extends UniValidator |
140 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
141 |
0 |
@Override... |
142 |
|
public int validate(StringLike s, int from, int to) |
143 |
|
{ |
144 |
0 |
return from < s.length() && Prop.isCurrency(s.charAt(from)) ? to : -1; |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
149 |
|
class NUnicodeCurrency extends UniValidator |
150 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
151 |
0 |
@Override... |
152 |
|
public int validate(StringLike s, int from, int to) |
153 |
|
{ |
154 |
0 |
return from < s.length() && !Prop.isCurrency(s.charAt(from)) ? to : -1; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
159 |
|
class UnicodeAlpha extends UniValidator |
160 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
161 |
0 |
@Override... |
162 |
|
public int validate(StringLike s, int from, int to) |
163 |
|
{ |
164 |
0 |
return from < s.length() && Prop.isAlphabetic(s.charAt(from)) ? to : -1; |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 3 |
|
169 |
|
class NUnicodeAlpha extends UniValidator |
170 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
171 |
0 |
@Override... |
172 |
|
public int validate(StringLike s, int from, int to) |
173 |
|
{ |
174 |
0 |
return from < s.length() && !Prop.isAlphabetic(s.charAt(from)) ? to |
175 |
|
: -1; |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 4 |
Complexity Density: 2 |
|
180 |
|
class UnicodeUpper extends UniValidator |
181 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
182 |
0 |
@Override... |
183 |
|
public int validate(StringLike s, int from, int to) |
184 |
|
{ |
185 |
0 |
return from < s.length() && isUpper(s.charAt(from)) ? to : -1; |
186 |
|
} |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
0 |
final boolean isUpper(char c)... |
189 |
|
{ |
190 |
0 |
return c == CaseMgr.toUpperCase(c) && c != CaseMgr.toLowerCase(c); |
191 |
|
} |
192 |
|
} |
193 |
|
|
194 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 4 |
Complexity Density: 2 |
|
195 |
|
class UnicodeLower extends UniValidator |
196 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
197 |
0 |
@Override... |
198 |
|
public int validate(StringLike s, int from, int to) |
199 |
|
{ |
200 |
0 |
return from < s.length() && isLower(s.charAt(from)) ? to : -1; |
201 |
|
} |
202 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
203 |
0 |
final boolean isLower(char c)... |
204 |
|
{ |
205 |
0 |
return c != CaseMgr.toUpperCase(c) && c == CaseMgr.toLowerCase(c); |
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 |
|
@author |
306 |
|
@version |
307 |
|
@see |
308 |
|
|
|
|
| 45.1% |
Uncovered Elements: 604 (1,100) |
Complexity: 321 |
Complexity Density: 0.49 |
|
309 |
|
public class Regex extends RegRes implements FilenameFilter |
310 |
|
{ |
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
static int BackRefOffset = 1; |
316 |
|
|
317 |
|
private static Pattern none = new NoPattern(); |
318 |
|
|
319 |
|
Pattern thePattern = none; |
320 |
|
|
321 |
|
patInt minMatch = new patInt(0); |
322 |
|
|
323 |
|
static Hashtable validators = new Hashtable(); |
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
|
324 |
10 |
static... |
325 |
|
{ |
326 |
10 |
define("p", "(?>1)", new UnicodePunct()); |
327 |
10 |
define("P", "(?>1)", new NUnicodePunct()); |
328 |
10 |
define("s", "(?>1)", new UnicodeWhite()); |
329 |
10 |
define("S", "(?>1)", new NUnicodeWhite()); |
330 |
10 |
define("w", "(?>1)", new UnicodeW()); |
331 |
10 |
define("W", "(?>1)", new NUnicodeW()); |
332 |
10 |
define("d", "(?>1)", new UnicodeDigit()); |
333 |
10 |
define("D", "(?>1)", new NUnicodeDigit()); |
334 |
10 |
define("m", "(?>1)", new UnicodeMath()); |
335 |
10 |
define("M", "(?>1)", new NUnicodeMath()); |
336 |
10 |
define("c", "(?>1)", new UnicodeCurrency()); |
337 |
10 |
define("C", "(?>1)", new NUnicodeCurrency()); |
338 |
10 |
define("a", "(?>1)", new UnicodeAlpha()); |
339 |
10 |
define("A", "(?>1)", new NUnicodeAlpha()); |
340 |
10 |
define("uc", "(?>1)", new UnicodeUpper()); |
341 |
10 |
define("lc", "(?>1)", new UnicodeLower()); |
342 |
|
} |
343 |
|
|
344 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
345 |
0 |
public void setDontMatchInQuotes(boolean b)... |
346 |
|
{ |
347 |
0 |
dontMatchInQuotes = b; |
348 |
|
} |
349 |
|
|
350 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
351 |
0 |
public boolean getDontMatchInQuotes()... |
352 |
|
{ |
353 |
0 |
return dontMatchInQuotes; |
354 |
|
} |
355 |
|
|
356 |
|
boolean dontMatchInQuotes = false; |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
362 |
227 |
public void setIgnoreCase(boolean b)... |
363 |
|
{ |
364 |
227 |
ignoreCase = b; |
365 |
|
} |
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
371 |
0 |
public boolean getIgnoreCase()... |
372 |
|
{ |
373 |
0 |
return ignoreCase; |
374 |
|
} |
375 |
|
|
376 |
|
boolean ignoreCase = false; |
377 |
|
|
378 |
|
static boolean defaultMFlag = false; |
379 |
|
|
380 |
|
|
381 |
|
|
382 |
|
|
383 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
384 |
0 |
public static void setDefaultMFlag(boolean mFlag)... |
385 |
|
{ |
386 |
0 |
defaultMFlag = mFlag; |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
393 |
0 |
public static boolean getDefaultMFlag()... |
394 |
|
{ |
395 |
0 |
return defaultMFlag; |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
@see |
403 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
404 |
2847 |
public Regex()... |
405 |
|
{ |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
@see |
416 |
|
@see |
417 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 2 |
Complexity Density: 1 |
|
418 |
2143 |
public Regex(String s)... |
419 |
|
{ |
420 |
2143 |
try |
421 |
|
{ |
422 |
2143 |
compile(s); |
423 |
|
} catch (RegSyntax rs) |
424 |
|
{ |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
|
ReplaceRule rep = null; |
429 |
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
@see |
434 |
|
@see |
435 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
436 |
96 |
public Regex(String s, String rp)... |
437 |
|
{ |
438 |
96 |
this(s); |
439 |
96 |
rep = ReplaceRule.perlCode(rp); |
440 |
|
} |
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
446 |
|
|
447 |
|
@see |
448 |
|
@see |
449 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
450 |
0 |
public Regex(String s, ReplaceRule rp)... |
451 |
|
{ |
452 |
0 |
this(s); |
453 |
0 |
rep = rp; |
454 |
|
} |
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
|
459 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
460 |
0 |
public void setReplaceRule(String rp)... |
461 |
|
{ |
462 |
0 |
rep = ReplaceRule.perlCode(rp); |
463 |
0 |
repr = null; |
464 |
|
} |
465 |
|
|
466 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
467 |
109 |
public void setReplaceRule(ReplaceRule rp)... |
468 |
|
{ |
469 |
109 |
rep = rp; |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
@see |
476 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
477 |
0 |
public static boolean isDefined(String nm)... |
478 |
|
{ |
479 |
0 |
return validators.get(nm) != null; |
480 |
|
} |
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
@see |
486 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
487 |
0 |
public static void undefine(String nm)... |
488 |
|
{ |
489 |
0 |
validators.remove(nm); |
490 |
|
} |
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
496 |
160 |
public static void define(String nm, String pat, Validator v)... |
497 |
|
{ |
498 |
160 |
v.pattern = pat; |
499 |
160 |
validators.put(nm, v); |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
506 |
0 |
public static void define(String nm, String pat)... |
507 |
|
{ |
508 |
0 |
validators.put(nm, pat); |
509 |
|
} |
510 |
|
|
511 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
512 |
3 |
public ReplaceRule getReplaceRule()... |
513 |
|
{ |
514 |
3 |
return rep; |
515 |
|
} |
516 |
|
|
517 |
|
Replacer repr = null; |
518 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
519 |
152 |
final Replacer _getReplacer()... |
520 |
|
{ |
521 |
152 |
return repr == null ? repr = new Replacer() : repr; |
522 |
|
} |
523 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
524 |
0 |
public Replacer getReplacer()... |
525 |
|
{ |
526 |
0 |
if (repr == null) |
527 |
|
{ |
528 |
0 |
repr = new Replacer(); |
529 |
|
} |
530 |
0 |
repr.rh.me = this; |
531 |
0 |
repr.rh.prev = null; |
532 |
0 |
return repr; |
533 |
|
} |
534 |
|
|
535 |
|
|
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
@see |
540 |
|
@see |
541 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
542 |
0 |
public String replaceFirst(String s)... |
543 |
|
{ |
544 |
0 |
return _getReplacer().replaceFirstRegion(s, this, 0, s.length()) |
545 |
|
.toString(); |
546 |
|
} |
547 |
|
|
548 |
|
|
549 |
|
|
550 |
|
|
551 |
|
|
552 |
|
@see |
553 |
|
@see |
554 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
555 |
0 |
public String replaceFirstFrom(String s, int pos)... |
556 |
|
{ |
557 |
0 |
return _getReplacer().replaceFirstRegion(s, this, pos, s.length()) |
558 |
|
.toString(); |
559 |
|
} |
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
|
564 |
|
|
565 |
|
@see |
566 |
|
@see |
567 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
568 |
0 |
public String replaceFirstRegion(String s, int start, int end)... |
569 |
|
{ |
570 |
0 |
return _getReplacer().replaceFirstRegion(s, this, start, end) |
571 |
|
.toString(); |
572 |
|
} |
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
@see |
579 |
|
@see |
580 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
581 |
152 |
public String replaceAll(String s)... |
582 |
|
{ |
583 |
152 |
return _getReplacer().replaceAllRegion(s, this, 0, s.length()) |
584 |
|
.toString(); |
585 |
|
} |
586 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
587 |
0 |
public StringLike replaceAll(StringLike s)... |
588 |
|
{ |
589 |
0 |
return _getReplacer().replaceAllRegion(s, this, 0, s.length()); |
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
@see |
597 |
|
@see |
598 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
599 |
0 |
public String replaceAllFrom(String s, int pos)... |
600 |
|
{ |
601 |
0 |
return _getReplacer().replaceAllRegion(s, this, pos, s.length()) |
602 |
|
.toString(); |
603 |
|
} |
604 |
|
|
605 |
|
|
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
@see |
610 |
|
@see |
611 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
612 |
0 |
public String replaceAllRegion(String s, int start, int end)... |
613 |
|
{ |
614 |
0 |
return _getReplacer().replaceAllRegion(s, this, start, end).toString(); |
615 |
|
} |
616 |
|
|
617 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
618 |
202 |
public Regex(Regex r)... |
619 |
|
{ |
620 |
202 |
super(r); |
621 |
202 |
dontMatchInQuotes = r.dontMatchInQuotes; |
622 |
202 |
esc = r.esc; |
623 |
202 |
ignoreCase = r.ignoreCase; |
624 |
202 |
gFlag = r.gFlag; |
625 |
202 |
if (r.rep == null) |
626 |
|
{ |
627 |
202 |
rep = null; |
628 |
|
} |
629 |
|
else |
630 |
|
{ |
631 |
0 |
rep = (ReplaceRule) r.rep.clone(); |
632 |
|
} |
633 |
|
|
634 |
|
|
635 |
|
|
636 |
202 |
thePattern = r.thePattern.clone(new Hashtable()); |
637 |
202 |
minMatch = r.minMatch; |
638 |
202 |
skipper = r.skipper; |
639 |
|
} |
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
public char esc = Pattern.ESC; |
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
|
650 |
|
|
651 |
|
@exception |
652 |
|
|
653 |
|
|
654 |
|
@see |
655 |
|
@see |
656 |
|
|
|
|
| 67.7% |
Uncovered Elements: 10 (31) |
Complexity: 5 |
Complexity Density: 0.22 |
|
657 |
2253 |
public void compile(String prepat) throws RegSyntax... |
658 |
|
{ |
659 |
2253 |
String postpat = parsePerl.codify(prepat, true); |
660 |
2253 |
String pat = postpat == null ? prepat : postpat; |
661 |
2253 |
minMatch = null; |
662 |
2253 |
ignoreCase = false; |
663 |
2253 |
dontMatchInQuotes = false; |
664 |
2253 |
Rthings mk = new Rthings(this); |
665 |
2253 |
int offset = mk.val; |
666 |
2253 |
String newpat = pat; |
667 |
2253 |
thePattern = none; |
668 |
2253 |
p = null; |
669 |
2253 |
or = null; |
670 |
2253 |
minMatch = new patInt(0); |
671 |
2253 |
StrPos sp = new StrPos(pat, 0); |
672 |
2253 |
if (sp.incMatch("(?e=")) |
673 |
|
{ |
674 |
0 |
char newEsc = sp.c; |
675 |
0 |
sp.inc(); |
676 |
0 |
if (sp.match(')')) |
677 |
|
{ |
678 |
0 |
newpat = reEscape(pat.substring(6), newEsc, Pattern.ESC); |
679 |
|
} |
680 |
|
} |
681 |
2253 |
else if (esc != Pattern.ESC) |
682 |
|
{ |
683 |
0 |
newpat = reEscape(pat, esc, Pattern.ESC); |
684 |
|
} |
685 |
2253 |
thePattern = _compile(newpat, mk); |
686 |
2252 |
numSubs_ = mk.val - offset; |
687 |
2252 |
mk.set(this); |
688 |
|
} |
689 |
|
|
690 |
|
|
691 |
|
|
692 |
|
|
693 |
|
|
694 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
695 |
0 |
@Override... |
696 |
|
public boolean equals(Object o) |
697 |
|
{ |
698 |
0 |
if (o instanceof Regex) |
699 |
|
{ |
700 |
0 |
if (toString().equals(o.toString())) |
701 |
|
{ |
702 |
0 |
return super.equals(o); |
703 |
|
} |
704 |
|
else |
705 |
|
{ |
706 |
0 |
return false; |
707 |
|
} |
708 |
|
} |
709 |
|
else |
710 |
|
{ |
711 |
0 |
return super.equals(o); |
712 |
|
} |
713 |
|
} |
714 |
|
|
715 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
716 |
202 |
@Override... |
717 |
|
public Object clone() |
718 |
|
{ |
719 |
202 |
return new Regex(this); |
720 |
|
} |
721 |
|
|
722 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
723 |
0 |
public RegRes result()... |
724 |
|
{ |
725 |
0 |
return (RegRes) super.clone(); |
726 |
|
} |
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
|
Pthings pt = new Pthings(); |
732 |
|
|
|
|
| 91.2% |
Uncovered Elements: 3 (34) |
Complexity: 8 |
Complexity Density: 0.4 |
|
733 |
11724 |
final Pthings prep(StringLike s)... |
734 |
|
{ |
735 |
|
|
736 |
11724 |
pt.lastPos = matchedTo(); |
737 |
11724 |
if (pt.lastPos < 0) |
738 |
|
{ |
739 |
6539 |
pt.lastPos = 0; |
740 |
|
} |
741 |
11724 |
if ((s == null ? null : s.unwrap()) != (src == null ? null |
742 |
|
: s.unwrap())) |
743 |
|
{ |
744 |
1898 |
pt.lastPos = 0; |
745 |
|
} |
746 |
11724 |
src = s; |
747 |
11724 |
pt.dotDoesntMatchCR = dotDoesntMatchCR && (!sFlag); |
748 |
11724 |
pt.mFlag = (mFlag | defaultMFlag); |
749 |
11724 |
pt.ignoreCase = ignoreCase; |
750 |
11724 |
pt.no_check = false; |
751 |
11724 |
if (pt.marks != null) |
752 |
|
{ |
753 |
37259 |
for (int i = 0; i < pt.marks.length; i++) |
754 |
|
{ |
755 |
32568 |
pt.marks[i] = -1; |
756 |
|
} |
757 |
|
} |
758 |
11724 |
pt.marks = null; |
759 |
11724 |
pt.nMarks = numSubs_; |
760 |
11724 |
pt.src = s; |
761 |
11724 |
if (dontMatchInQuotes) |
762 |
|
{ |
763 |
0 |
setCbits(s, pt); |
764 |
|
} |
765 |
|
else |
766 |
|
{ |
767 |
11724 |
pt.cbits = null; |
768 |
|
} |
769 |
11724 |
return pt; |
770 |
|
} |
771 |
|
|
772 |
|
|
773 |
|
|
774 |
|
|
775 |
|
|
776 |
|
@see |
777 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
778 |
0 |
public boolean matchAt(String s, int start_pos)... |
779 |
|
{ |
780 |
0 |
return _search(s, start_pos, start_pos); |
781 |
|
} |
782 |
|
|
783 |
|
|
784 |
|
|
785 |
|
|
786 |
|
|
787 |
|
@see |
788 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
789 |
0 |
public boolean matchAt(StringLike s, int start_pos)... |
790 |
|
{ |
791 |
0 |
return _search(s, start_pos, start_pos); |
792 |
|
} |
793 |
|
|
794 |
|
|
795 |
|
|
796 |
|
|
797 |
|
@see |
798 |
|
@see |
799 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
800 |
10490 |
public boolean search(String s)... |
801 |
|
{ |
802 |
10490 |
if (s == null) |
803 |
|
{ |
804 |
0 |
throw new NullPointerException(MessageManager |
805 |
|
.getString("exception.null_string_given_to_regex_search")); |
806 |
|
} |
807 |
10490 |
return _search(s, 0, s.length()); |
808 |
|
} |
809 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
810 |
0 |
public boolean search(StringLike sl)... |
811 |
|
{ |
812 |
0 |
if (sl == null) |
813 |
|
{ |
814 |
0 |
throw new NullPointerException(MessageManager.getString( |
815 |
|
"exception.null_string_like_given_to_regex_search")); |
816 |
|
} |
817 |
0 |
return _search(sl, 0, sl.length()); |
818 |
|
} |
819 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
820 |
0 |
public boolean reverseSearch(String s)... |
821 |
|
{ |
822 |
0 |
if (s == null) |
823 |
|
{ |
824 |
0 |
throw new NullPointerException(MessageManager.getString( |
825 |
|
"exception.null_string_given_to_regex_reverse_search")); |
826 |
|
} |
827 |
0 |
return _reverseSearch(s, 0, s.length()); |
828 |
|
} |
829 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
830 |
0 |
public boolean reverseSearch(StringLike sl)... |
831 |
|
{ |
832 |
0 |
if (sl == null) |
833 |
|
{ |
834 |
0 |
throw new NullPointerException(MessageManager.getString( |
835 |
|
"exception.null_string_like_given_to_regex_reverse_search")); |
836 |
|
} |
837 |
0 |
return _reverseSearch(sl, 0, sl.length()); |
838 |
|
} |
839 |
|
|
840 |
|
|
841 |
|
|
842 |
|
|
843 |
|
|
844 |
|
|
845 |
|
|
846 |
|
|
847 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
848 |
1079 |
public boolean searchFrom(String s, int start)... |
849 |
|
{ |
850 |
1079 |
if (s == null) |
851 |
|
{ |
852 |
0 |
throw new NullPointerException(MessageManager.getString( |
853 |
|
"exception.null_string_like_given_to_regex_search_from")); |
854 |
|
} |
855 |
1079 |
return _search(s, start, s.length()); |
856 |
|
} |
857 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
858 |
0 |
public boolean searchFrom(StringLike s, int start)... |
859 |
|
{ |
860 |
0 |
if (s == null) |
861 |
|
{ |
862 |
0 |
throw new NullPointerException(MessageManager.getString( |
863 |
|
"exception.null_string_like_given_to_regex_search_from")); |
864 |
|
} |
865 |
0 |
return _search(s, start, s.length()); |
866 |
|
} |
867 |
|
|
868 |
|
|
869 |
|
|
870 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
871 |
0 |
public boolean searchRegion(String s, int start, int end)... |
872 |
|
{ |
873 |
0 |
if (s == null) |
874 |
|
{ |
875 |
0 |
throw new NullPointerException(MessageManager.getString( |
876 |
|
"exception.null_string_like_given_to_regex_search_region")); |
877 |
|
} |
878 |
0 |
return _search(s, start, end); |
879 |
|
} |
880 |
|
|
881 |
|
|
882 |
|
|
883 |
|
|
884 |
|
|
885 |
|
public static boolean dotDoesntMatchCR = true; |
886 |
|
|
887 |
|
StringLike gFlags; |
888 |
|
|
889 |
|
int gFlagto = 0; |
890 |
|
|
891 |
|
boolean gFlag = false; |
892 |
|
|
893 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
894 |
0 |
public void setGFlag(boolean b)... |
895 |
|
{ |
896 |
0 |
gFlag = b; |
897 |
|
} |
898 |
|
|
899 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
900 |
0 |
public boolean getGFlag()... |
901 |
|
{ |
902 |
0 |
return gFlag; |
903 |
|
} |
904 |
|
|
905 |
|
boolean sFlag = false; |
906 |
|
|
907 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
908 |
0 |
public boolean getSFlag()... |
909 |
|
{ |
910 |
0 |
return sFlag; |
911 |
|
} |
912 |
|
|
913 |
|
boolean mFlag = false; |
914 |
|
|
915 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
916 |
0 |
public boolean getMFlag()... |
917 |
|
{ |
918 |
0 |
return mFlag; |
919 |
|
} |
920 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
921 |
11569 |
final boolean _search(String s, int start, int end)... |
922 |
|
{ |
923 |
11569 |
return _search(new StringWrap(s), start, end); |
924 |
|
} |
925 |
|
|
|
|
| 89.6% |
Uncovered Elements: 5 (48) |
Complexity: 14 |
Complexity Density: 0.47 |
|
926 |
11724 |
final boolean _search(StringLike s, int start, int end)... |
927 |
|
{ |
928 |
11724 |
if (gFlag && gFlagto > 0 && gFlags != null |
929 |
|
&& s.unwrap() == gFlags.unwrap()) |
930 |
|
{ |
931 |
0 |
start = gFlagto; |
932 |
|
} |
933 |
11724 |
gFlags = null; |
934 |
|
|
935 |
11724 |
Pthings pt = prep(s); |
936 |
|
|
937 |
11724 |
int up = (minMatch == null ? end : end - minMatch.i); |
938 |
|
|
939 |
11724 |
if (up < start && end >= start) |
940 |
|
{ |
941 |
0 |
up = start; |
942 |
|
} |
943 |
|
|
944 |
11724 |
if (skipper == null) |
945 |
|
{ |
946 |
265014 |
for (int i = start; i <= up; i++) |
947 |
|
{ |
948 |
260628 |
charsMatched_ = thePattern.matchAt(s, i, pt); |
949 |
260628 |
if (charsMatched_ >= 0) |
950 |
|
{ |
951 |
4850 |
matchFrom_ = thePattern.mfrom; |
952 |
4850 |
marks = pt.marks; |
953 |
4850 |
gFlagto = matchFrom_ + charsMatched_; |
954 |
4850 |
gFlags = s; |
955 |
4850 |
return didMatch_ = true; |
956 |
|
} |
957 |
|
} |
958 |
|
} |
959 |
|
else |
960 |
|
{ |
961 |
2488 |
pt.no_check = true; |
962 |
127967 |
for (int i = start; i <= up; i++) |
963 |
|
{ |
964 |
127967 |
i = skipper.find(src, i, up); |
965 |
127967 |
if (i < 0) |
966 |
|
{ |
967 |
926 |
charsMatched_ = matchFrom_ = -1; |
968 |
926 |
return didMatch_ = false; |
969 |
|
} |
970 |
127041 |
charsMatched_ = thePattern.matchAt(s, i, pt); |
971 |
127041 |
if (charsMatched_ >= 0) |
972 |
|
{ |
973 |
1562 |
matchFrom_ = thePattern.mfrom; |
974 |
1562 |
marks = pt.marks; |
975 |
1562 |
gFlagto = matchFrom_ + charsMatched_; |
976 |
1562 |
gFlags = s; |
977 |
1562 |
return didMatch_ = true; |
978 |
|
} |
979 |
|
} |
980 |
|
} |
981 |
4386 |
return didMatch_ = false; |
982 |
|
} |
983 |
|
|
984 |
|
|
985 |
|
|
986 |
|
|
987 |
|
|
988 |
|
|
989 |
|
|
990 |
|
|
991 |
|
|
992 |
|
|
993 |
|
|
994 |
|
|
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
|
|
1002 |
|
|
1003 |
|
|
1004 |
|
|
1005 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1006 |
0 |
boolean _reverseSearch(String s, int start, int end)... |
1007 |
|
{ |
1008 |
0 |
return _reverseSearch(new StringWrap(s), start, end); |
1009 |
|
} |
1010 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
1011 |
0 |
boolean _reverseSearch(StringLike s, int start, int end)... |
1012 |
|
{ |
1013 |
0 |
if (gFlag && gFlagto > 0 && s.unwrap() == gFlags.unwrap()) |
1014 |
|
{ |
1015 |
0 |
end = gFlagto; |
1016 |
|
} |
1017 |
0 |
gFlags = null; |
1018 |
0 |
Pthings pt = prep(s); |
1019 |
0 |
for (int i = end; i >= start; i--) |
1020 |
|
{ |
1021 |
0 |
charsMatched_ = thePattern.matchAt(s, i, pt); |
1022 |
0 |
if (charsMatched_ >= 0) |
1023 |
|
{ |
1024 |
0 |
matchFrom_ = thePattern.mfrom; |
1025 |
0 |
marks = pt.marks; |
1026 |
0 |
gFlagto = matchFrom_ - 1; |
1027 |
0 |
gFlags = s; |
1028 |
0 |
return didMatch_ = true; |
1029 |
|
} |
1030 |
|
} |
1031 |
0 |
return didMatch_ = false; |
1032 |
|
} |
1033 |
|
|
1034 |
|
|
1035 |
|
|
1036 |
|
|
1037 |
|
|
1038 |
|
static StringLike lasts = null; |
1039 |
|
|
1040 |
|
static BitSet lastbs = null; |
1041 |
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 14 |
Complexity Density: 0.54 |
|
1042 |
0 |
static void setCbits(StringLike s, Pthings pt)... |
1043 |
|
{ |
1044 |
0 |
if (s == lasts) |
1045 |
|
{ |
1046 |
0 |
pt.cbits = lastbs; |
1047 |
0 |
return; |
1048 |
|
} |
1049 |
0 |
BitSet bs = new BitSet(s.length()); |
1050 |
0 |
char qc = ' '; |
1051 |
0 |
boolean setBit = false; |
1052 |
0 |
for (int i = 0; i < s.length(); i++) |
1053 |
|
{ |
1054 |
0 |
if (setBit) |
1055 |
|
{ |
1056 |
0 |
bs.set(i); |
1057 |
|
} |
1058 |
0 |
char c = s.charAt(i); |
1059 |
0 |
if (!setBit && c == '"') |
1060 |
|
{ |
1061 |
0 |
qc = c; |
1062 |
0 |
setBit = true; |
1063 |
0 |
bs.set(i); |
1064 |
|
} |
1065 |
0 |
else if (!setBit && c == '\'') |
1066 |
|
{ |
1067 |
0 |
qc = c; |
1068 |
0 |
setBit = true; |
1069 |
0 |
bs.set(i); |
1070 |
|
} |
1071 |
0 |
else if (setBit && c == qc) |
1072 |
|
{ |
1073 |
0 |
setBit = false; |
1074 |
|
} |
1075 |
0 |
else if (setBit && c == '\\' && i + 1 < s.length()) |
1076 |
|
{ |
1077 |
0 |
i++; |
1078 |
0 |
if (setBit) |
1079 |
|
{ |
1080 |
0 |
bs.set(i); |
1081 |
|
} |
1082 |
|
} |
1083 |
|
} |
1084 |
0 |
pt.cbits = lastbs = bs; |
1085 |
0 |
lasts = s; |
1086 |
|
} |
1087 |
|
|
1088 |
|
|
1089 |
|
|
|
|
| 40% |
Uncovered Elements: 3 (5) |
Complexity: 4 |
Complexity Density: 0.8 |
|
1090 |
2647 |
Regex newRegex()... |
1091 |
|
{ |
1092 |
2647 |
try |
1093 |
|
{ |
1094 |
2647 |
return getClass().getDeclaredConstructor().newInstance(); |
1095 |
|
} catch (InstantiationException ie) |
1096 |
|
{ |
1097 |
0 |
return null; |
1098 |
|
} catch (IllegalAccessException iae) |
1099 |
|
{ |
1100 |
0 |
return null; |
1101 |
|
} catch (ReflectiveOperationException roe) |
1102 |
|
{ |
1103 |
0 |
return null; |
1104 |
|
} |
1105 |
|
} |
1106 |
|
|
1107 |
|
|
1108 |
|
|
1109 |
|
|
1110 |
|
|
1111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
1112 |
11174 |
protected void add(Pattern p2)... |
1113 |
|
{ |
1114 |
11174 |
if (p == null) |
1115 |
|
{ |
1116 |
5064 |
p = p2; |
1117 |
|
} |
1118 |
|
else |
1119 |
|
{ |
1120 |
6110 |
p.add(p2); |
1121 |
6110 |
p2 = p; |
1122 |
|
} |
1123 |
|
} |
1124 |
|
|
1125 |
|
|
1126 |
|
|
1127 |
|
|
1128 |
|
|
1129 |
|
|
1130 |
|
|
1131 |
|
|
1132 |
|
|
1133 |
|
@exception |
1134 |
|
|
1135 |
|
|
1136 |
|
|
|
|
| 46.3% |
Uncovered Elements: 203 (378) |
Complexity: 95 |
Complexity Density: 0.42 |
|
1137 |
15612 |
protected void compile1(StrPos sp, Rthings mk) throws RegSyntax... |
1138 |
|
{ |
1139 |
15612 |
if (sp.match('[')) |
1140 |
|
{ |
1141 |
2176 |
sp.inc(); |
1142 |
2176 |
add(matchBracket(sp)); |
1143 |
|
} |
1144 |
13436 |
else if (sp.match('|')) |
1145 |
|
{ |
1146 |
179 |
if (or == null) |
1147 |
|
{ |
1148 |
15 |
or = new Or(); |
1149 |
|
} |
1150 |
179 |
if (p == null) |
1151 |
|
{ |
1152 |
0 |
p = new NullPattern(); |
1153 |
|
} |
1154 |
179 |
or.addOr(p); |
1155 |
179 |
p = null; |
1156 |
|
} |
1157 |
13257 |
else if (sp.incMatch("(?<")) |
1158 |
|
{ |
1159 |
0 |
patInt i = sp.getPatInt(); |
1160 |
0 |
if (i == null) |
1161 |
|
{ |
1162 |
0 |
RegSyntaxError.endItAll("No int after (?<"); |
1163 |
|
} |
1164 |
0 |
add(new Backup(i.intValue())); |
1165 |
0 |
if (!sp.match(')')) |
1166 |
|
{ |
1167 |
0 |
RegSyntaxError.endItAll("No ) after (?<"); |
1168 |
|
} |
1169 |
|
} |
1170 |
13257 |
else if (sp.incMatch("(?>")) |
1171 |
|
{ |
1172 |
0 |
patInt i = sp.getPatInt(); |
1173 |
0 |
if (i == null) |
1174 |
|
{ |
1175 |
0 |
RegSyntaxError.endItAll("No int after (?>"); |
1176 |
|
} |
1177 |
0 |
add(new Backup(-i.intValue())); |
1178 |
0 |
if (!sp.match(')')) |
1179 |
|
{ |
1180 |
0 |
RegSyntaxError.endItAll("No ) after (?<"); |
1181 |
|
} |
1182 |
|
} |
1183 |
13257 |
else if (sp.incMatch("(?@")) |
1184 |
|
{ |
1185 |
0 |
char op = sp.c; |
1186 |
0 |
sp.inc(); |
1187 |
0 |
char cl = sp.c; |
1188 |
0 |
sp.inc(); |
1189 |
0 |
if (!sp.match(')')) |
1190 |
|
{ |
1191 |
0 |
RegSyntaxError.endItAll("(?@ does not have closing paren"); |
1192 |
|
} |
1193 |
0 |
add(new Group(op, cl)); |
1194 |
|
} |
1195 |
13257 |
else if (sp.incMatch("(?#")) |
1196 |
|
{ |
1197 |
0 |
while (!sp.match(')')) |
1198 |
|
{ |
1199 |
0 |
sp.inc(); |
1200 |
|
} |
1201 |
|
} |
1202 |
13257 |
else if (sp.dontMatch && sp.c == 'w') |
1203 |
|
{ |
1204 |
|
|
1205 |
|
|
1206 |
|
|
1207 |
155 |
Bracket b = new Bracket(false); |
1208 |
155 |
b.addOr(new Range('a', 'z')); |
1209 |
155 |
b.addOr(new Range('A', 'Z')); |
1210 |
155 |
b.addOr(new Range('0', '9')); |
1211 |
155 |
b.addOr(new oneChar('_')); |
1212 |
155 |
add(b); |
1213 |
|
} |
1214 |
13102 |
else if (sp.dontMatch && sp.c == 'G') |
1215 |
|
{ |
1216 |
0 |
add(new BackG()); |
1217 |
|
} |
1218 |
13102 |
else if (sp.dontMatch && sp.c == 's') |
1219 |
|
{ |
1220 |
|
|
1221 |
|
|
1222 |
|
|
1223 |
1265 |
Bracket b = new Bracket(false); |
1224 |
1265 |
b.addOr(new oneChar((char) 32)); |
1225 |
1265 |
b.addOr(new Range((char) 8, (char) 10)); |
1226 |
1265 |
b.addOr(new oneChar((char) 13)); |
1227 |
1265 |
add(b); |
1228 |
|
} |
1229 |
11837 |
else if (sp.dontMatch && sp.c == 'd') |
1230 |
|
{ |
1231 |
|
|
1232 |
|
|
1233 |
|
|
1234 |
116 |
Range digit = new Range('0', '9'); |
1235 |
116 |
digit.printBrackets = true; |
1236 |
116 |
add(digit); |
1237 |
|
} |
1238 |
11721 |
else if (sp.dontMatch && sp.c == 'W') |
1239 |
|
{ |
1240 |
|
|
1241 |
|
|
1242 |
|
|
1243 |
1 |
Bracket b = new Bracket(true); |
1244 |
1 |
b.addOr(new Range('a', 'z')); |
1245 |
1 |
b.addOr(new Range('A', 'Z')); |
1246 |
1 |
b.addOr(new Range('0', '9')); |
1247 |
1 |
b.addOr(new oneChar('_')); |
1248 |
1 |
add(b); |
1249 |
|
} |
1250 |
11720 |
else if (sp.dontMatch && sp.c == 'S') |
1251 |
|
{ |
1252 |
|
|
1253 |
|
|
1254 |
|
|
1255 |
240 |
Bracket b = new Bracket(true); |
1256 |
240 |
b.addOr(new oneChar((char) 32)); |
1257 |
240 |
b.addOr(new Range((char) 8, (char) 10)); |
1258 |
240 |
b.addOr(new oneChar((char) 13)); |
1259 |
240 |
add(b); |
1260 |
|
} |
1261 |
11480 |
else if (sp.dontMatch && sp.c == 'D') |
1262 |
|
{ |
1263 |
|
|
1264 |
|
|
1265 |
|
|
1266 |
0 |
Bracket b = new Bracket(true); |
1267 |
0 |
b.addOr(new Range('0', '9')); |
1268 |
0 |
add(b); |
1269 |
|
} |
1270 |
11480 |
else if (sp.dontMatch && sp.c == 'B') |
1271 |
|
{ |
1272 |
0 |
Regex r = new Regex(); |
1273 |
0 |
r._compile("(?!" + back_slash + "b)", mk); |
1274 |
0 |
add(r.thePattern); |
1275 |
|
} |
1276 |
11480 |
else if (isOctalString(sp)) |
1277 |
|
{ |
1278 |
0 |
int d = sp.c - '0'; |
1279 |
0 |
sp.inc(); |
1280 |
0 |
d = 8 * d + sp.c - '0'; |
1281 |
0 |
StrPos sp2 = new StrPos(sp); |
1282 |
0 |
sp2.inc(); |
1283 |
0 |
if (isOctalDigit(sp2, false)) |
1284 |
|
{ |
1285 |
0 |
sp.inc(); |
1286 |
0 |
d = 8 * d + sp.c - '0'; |
1287 |
|
} |
1288 |
0 |
add(new oneChar((char) d)); |
1289 |
|
} |
1290 |
11480 |
else if (sp.dontMatch && sp.c >= '1' && sp.c <= '9') |
1291 |
|
{ |
1292 |
0 |
int iv = sp.c - '0'; |
1293 |
0 |
StrPos s2 = new StrPos(sp); |
1294 |
0 |
s2.inc(); |
1295 |
0 |
if (!s2.dontMatch && s2.c >= '0' && s2.c <= '9') |
1296 |
|
{ |
1297 |
0 |
iv = 10 * iv + (s2.c - '0'); |
1298 |
0 |
sp.inc(); |
1299 |
|
} |
1300 |
0 |
add(new BackMatch(iv)); |
1301 |
|
} |
1302 |
11480 |
else if (sp.dontMatch && sp.c == 'b') |
1303 |
|
{ |
1304 |
396 |
add(new Boundary()); |
1305 |
|
} |
1306 |
11084 |
else if (sp.match('\b')) |
1307 |
|
{ |
1308 |
0 |
add(new Boundary()); |
1309 |
|
} |
1310 |
11084 |
else if (sp.match('$')) |
1311 |
|
{ |
1312 |
31 |
add(new End(true)); |
1313 |
|
} |
1314 |
11053 |
else if (sp.dontMatch && sp.c == 'Z') |
1315 |
|
{ |
1316 |
0 |
add(new End(false)); |
1317 |
|
} |
1318 |
11053 |
else if (sp.match('.')) |
1319 |
|
{ |
1320 |
387 |
add(new Any()); |
1321 |
|
} |
1322 |
10666 |
else if (sp.incMatch("(??")) |
1323 |
|
{ |
1324 |
0 |
StringBuffer sb = new StringBuffer(); |
1325 |
0 |
StringBuffer sb2 = new StringBuffer(); |
1326 |
0 |
while (!sp.match(')') && !sp.match(':')) |
1327 |
|
{ |
1328 |
0 |
sb.append(sp.c); |
1329 |
0 |
sp.inc(); |
1330 |
|
} |
1331 |
0 |
if (sp.incMatch(":")) |
1332 |
|
{ |
1333 |
0 |
while (!sp.match(')')) |
1334 |
|
{ |
1335 |
0 |
sb2.append(sp.c); |
1336 |
0 |
sp.inc(); |
1337 |
|
} |
1338 |
|
} |
1339 |
0 |
String sbs = sb.toString(); |
1340 |
0 |
if (validators.get(sbs) instanceof String) |
1341 |
|
{ |
1342 |
0 |
String pat = (String) validators.get(sbs); |
1343 |
0 |
Regex r = newRegex(); |
1344 |
0 |
Rthings rth = new Rthings(this); |
1345 |
0 |
rth.noBackRefs = true; |
1346 |
0 |
r._compile(pat, rth); |
1347 |
0 |
add(r.thePattern); |
1348 |
|
} |
1349 |
|
else |
1350 |
|
{ |
1351 |
0 |
Custom cm = new Custom(sb.toString()); |
1352 |
0 |
if (cm.v != null) |
1353 |
|
{ |
1354 |
0 |
Validator v2 = cm.v.arg(sb2.toString()); |
1355 |
0 |
if (v2 != null) |
1356 |
|
{ |
1357 |
0 |
v2.argsave = sb2.toString(); |
1358 |
0 |
String p = cm.v.pattern; |
1359 |
0 |
cm.v = v2; |
1360 |
0 |
v2.pattern = p; |
1361 |
|
} |
1362 |
0 |
Regex r = newRegex(); |
1363 |
0 |
Rthings rth = new Rthings(this); |
1364 |
0 |
rth.noBackRefs = true; |
1365 |
0 |
r._compile(cm.v.pattern, rth); |
1366 |
0 |
cm.sub = r.thePattern; |
1367 |
0 |
cm.sub.add(new CustomEndpoint(cm)); |
1368 |
0 |
cm.sub.setParent(cm); |
1369 |
0 |
add(cm); |
1370 |
|
} |
1371 |
|
} |
1372 |
|
} |
1373 |
10666 |
else if (sp.match('(')) |
1374 |
|
{ |
1375 |
2647 |
mk.parenLevel++; |
1376 |
2647 |
Regex r = newRegex(); |
1377 |
|
|
1378 |
2647 |
sp.inc(); |
1379 |
2647 |
if (sp.incMatch("?:")) |
1380 |
|
{ |
1381 |
42 |
r.or = new Or(); |
1382 |
|
} |
1383 |
2605 |
else if (sp.incMatch("?=")) |
1384 |
|
{ |
1385 |
0 |
r.or = new lookAhead(false); |
1386 |
|
} |
1387 |
2605 |
else if (sp.incMatch("?!")) |
1388 |
|
{ |
1389 |
0 |
r.or = new lookAhead(true); |
1390 |
|
} |
1391 |
2605 |
else if (sp.match('?')) |
1392 |
|
{ |
1393 |
0 |
sp.inc(); |
1394 |
0 |
do |
1395 |
|
{ |
1396 |
0 |
if (sp.c == 'i') |
1397 |
|
{ |
1398 |
0 |
mk.ignoreCase = true; |
1399 |
|
} |
1400 |
0 |
if (sp.c == 'Q') |
1401 |
|
{ |
1402 |
0 |
mk.dontMatchInQuotes = true; |
1403 |
|
} |
1404 |
0 |
if (sp.c == 'o') |
1405 |
|
{ |
1406 |
0 |
mk.optimizeMe = true; |
1407 |
|
} |
1408 |
0 |
if (sp.c == 'g') |
1409 |
|
{ |
1410 |
0 |
mk.gFlag = true; |
1411 |
|
} |
1412 |
0 |
if (sp.c == 's') |
1413 |
|
{ |
1414 |
0 |
mk.sFlag = true; |
1415 |
|
} |
1416 |
0 |
if (sp.c == 'm') |
1417 |
|
{ |
1418 |
0 |
mk.mFlag = true; |
1419 |
|
} |
1420 |
0 |
sp.inc(); |
1421 |
0 |
} while (!sp.match(')') && !sp.eos); |
1422 |
0 |
r = null; |
1423 |
0 |
mk.parenLevel--; |
1424 |
0 |
if (sp.eos) |
1425 |
|
{ |
1426 |
0 |
RegSyntaxError.endItAll("Unclosed ()"); |
1427 |
|
} |
1428 |
|
} |
1429 |
|
else |
1430 |
|
{ |
1431 |
2605 |
r.or = mk.noBackRefs ? new Or() : new OrMark(mk.val++); |
1432 |
|
} |
1433 |
2647 |
if (r != null) |
1434 |
|
{ |
1435 |
2647 |
add(r._compile(sp, mk)); |
1436 |
|
} |
1437 |
|
} |
1438 |
8019 |
else if (sp.match('^')) |
1439 |
|
{ |
1440 |
68 |
add(new Start(true)); |
1441 |
|
} |
1442 |
7951 |
else if (sp.dontMatch && sp.c == 'A') |
1443 |
|
{ |
1444 |
0 |
add(new Start(false)); |
1445 |
|
} |
1446 |
7951 |
else if (sp.match('*')) |
1447 |
|
{ |
1448 |
1478 |
addMulti(new patInt(0), new patInf()); |
1449 |
|
} |
1450 |
6473 |
else if (sp.match('+')) |
1451 |
|
{ |
1452 |
2511 |
addMulti(new patInt(1), new patInf()); |
1453 |
|
} |
1454 |
3962 |
else if (sp.match('?')) |
1455 |
|
{ |
1456 |
92 |
addMulti(new patInt(0), new patInt(1)); |
1457 |
|
} |
1458 |
3870 |
else if (sp.match('{')) |
1459 |
|
{ |
1460 |
178 |
boolean bad = false; |
1461 |
178 |
StrPos sp2 = new StrPos(sp); |
1462 |
|
|
1463 |
178 |
sp.inc(); |
1464 |
178 |
patInt i1 = sp.getPatInt(); |
1465 |
178 |
patInt i2 = null; |
1466 |
178 |
if (sp.match('}')) |
1467 |
|
{ |
1468 |
163 |
i2 = i1; |
1469 |
|
} |
1470 |
|
else |
1471 |
|
{ |
1472 |
15 |
if (!sp.match(',')) |
1473 |
|
{ |
1474 |
|
|
1475 |
|
|
1476 |
|
|
1477 |
|
|
1478 |
0 |
bad = true; |
1479 |
|
} |
1480 |
15 |
sp.inc(); |
1481 |
15 |
if (sp.match('}')) |
1482 |
|
{ |
1483 |
15 |
i2 = new patInf(); |
1484 |
|
} |
1485 |
|
else |
1486 |
|
{ |
1487 |
0 |
i2 = sp.getPatInt(); |
1488 |
|
} |
1489 |
|
} |
1490 |
178 |
if (i1 == null || i2 == null) |
1491 |
|
{ |
1492 |
|
|
1493 |
|
|
1494 |
|
|
1495 |
0 |
bad = true; |
1496 |
|
} |
1497 |
178 |
if (bad) |
1498 |
|
{ |
1499 |
0 |
sp.dup(sp2); |
1500 |
0 |
add(new oneChar(sp.c)); |
1501 |
|
} |
1502 |
|
else |
1503 |
|
{ |
1504 |
178 |
addMulti(i1, i2); |
1505 |
|
} |
1506 |
|
} |
1507 |
3692 |
else if (sp.escMatch('x') && next2Hex(sp)) |
1508 |
|
{ |
1509 |
0 |
sp.inc(); |
1510 |
0 |
int d = getHexDigit(sp); |
1511 |
0 |
sp.inc(); |
1512 |
0 |
d = 16 * d + getHexDigit(sp); |
1513 |
0 |
add(new oneChar((char) d)); |
1514 |
|
} |
1515 |
3692 |
else if (sp.escMatch('c')) |
1516 |
|
{ |
1517 |
0 |
sp.inc(); |
1518 |
0 |
if (sp.c < Ctrl.cmap.length) |
1519 |
|
{ |
1520 |
0 |
add(new oneChar(Ctrl.cmap[sp.c])); |
1521 |
|
} |
1522 |
|
else |
1523 |
|
{ |
1524 |
0 |
add(new oneChar(sp.c)); |
1525 |
|
} |
1526 |
|
} |
1527 |
3692 |
else if (sp.escMatch('f')) |
1528 |
|
{ |
1529 |
0 |
add(new oneChar((char) 12)); |
1530 |
|
} |
1531 |
3692 |
else if (sp.escMatch('a')) |
1532 |
|
{ |
1533 |
0 |
add(new oneChar((char) 7)); |
1534 |
|
} |
1535 |
3692 |
else if (sp.escMatch('t')) |
1536 |
|
{ |
1537 |
0 |
add(new oneChar('\t')); |
1538 |
|
} |
1539 |
3692 |
else if (sp.escMatch('n')) |
1540 |
|
{ |
1541 |
0 |
add(new oneChar('\n')); |
1542 |
|
} |
1543 |
3692 |
else if (sp.escMatch('r')) |
1544 |
|
{ |
1545 |
0 |
add(new oneChar('\r')); |
1546 |
|
} |
1547 |
3692 |
else if (sp.escMatch('b')) |
1548 |
|
{ |
1549 |
0 |
add(new oneChar('\b')); |
1550 |
|
} |
1551 |
3692 |
else if (sp.escMatch('e')) |
1552 |
|
{ |
1553 |
0 |
add(new oneChar((char) 27)); |
1554 |
|
} |
1555 |
|
else |
1556 |
|
{ |
1557 |
3692 |
add(new oneChar(sp.c)); |
1558 |
3692 |
if (sp.match(')')) |
1559 |
|
{ |
1560 |
0 |
RegSyntaxError.endItAll("Unmatched right paren in pattern"); |
1561 |
|
} |
1562 |
|
} |
1563 |
|
} |
1564 |
|
|
1565 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
1566 |
2253 |
private Pattern _compile(String pat, Rthings mk) throws RegSyntax... |
1567 |
|
{ |
1568 |
2253 |
minMatch = null; |
1569 |
2253 |
sFlag = mFlag = ignoreCase = gFlag = false; |
1570 |
2253 |
StrPos sp = new StrPos(pat, 0); |
1571 |
2253 |
thePattern = _compile(sp, mk); |
1572 |
2252 |
pt.marks = null; |
1573 |
2252 |
return thePattern; |
1574 |
|
} |
1575 |
|
|
1576 |
|
Pattern p = null; |
1577 |
|
|
1578 |
|
Or or = null; |
1579 |
|
|
|
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 10 |
Complexity Density: 0.77 |
|
1580 |
4900 |
Pattern _compile(StrPos sp, Rthings mk) throws RegSyntax... |
1581 |
|
{ |
1582 |
20511 |
while (!(sp.eos || (or != null && sp.match(')')))) |
1583 |
|
{ |
1584 |
15612 |
compile1(sp, mk); |
1585 |
15611 |
sp.inc(); |
1586 |
|
} |
1587 |
4899 |
if (sp.match(')')) |
1588 |
|
{ |
1589 |
2647 |
mk.parenLevel--; |
1590 |
|
} |
1591 |
2252 |
else if (sp.eos && mk.parenLevel != 0) |
1592 |
|
{ |
1593 |
0 |
RegSyntaxError.endItAll("Unclosed Parenthesis! lvl=" + mk.parenLevel); |
1594 |
|
} |
1595 |
4899 |
if (or != null) |
1596 |
|
{ |
1597 |
2662 |
if (p == null) |
1598 |
|
{ |
1599 |
15 |
p = new NullPattern(); |
1600 |
|
} |
1601 |
2662 |
or.addOr(p); |
1602 |
2662 |
return or; |
1603 |
|
} |
1604 |
2237 |
return p == null ? new NullPattern() : p; |
1605 |
|
} |
1606 |
|
|
1607 |
|
|
1608 |
|
|
|
|
| 82.4% |
Uncovered Elements: 6 (34) |
Complexity: 19 |
Complexity Density: 1.06 |
|
1609 |
4259 |
void addMulti(patInt i1, patInt i2) throws RegSyntax... |
1610 |
|
{ |
1611 |
4259 |
Pattern last, last2; |
1612 |
8429 |
for (last = p; last != null && last.next != null; last = last.next) |
1613 |
|
{ |
1614 |
4170 |
; |
1615 |
|
} |
1616 |
4259 |
if (last == null || last == p) |
1617 |
|
{ |
1618 |
2624 |
last2 = null; |
1619 |
|
} |
1620 |
|
else |
1621 |
|
{ |
1622 |
4170 |
for (last2 = p; last2.next != last; last2 = last2.next) |
1623 |
|
{ |
1624 |
2535 |
; |
1625 |
|
} |
1626 |
|
} |
1627 |
4259 |
if (last instanceof Multi && i1.intValue() == 0 && i2.intValue() == 1) |
1628 |
|
{ |
1629 |
0 |
((Multi) last).matchFewest = true; |
1630 |
|
} |
1631 |
4259 |
else if (last instanceof FastMulti && i1.intValue() == 0 |
1632 |
|
&& i2.intValue() == 1) |
1633 |
|
{ |
1634 |
0 |
((FastMulti) last).matchFewest = true; |
1635 |
|
} |
1636 |
4259 |
else if (last instanceof DotMulti && i1.intValue() == 0 |
1637 |
|
&& i2.intValue() == 1) |
1638 |
|
{ |
1639 |
0 |
((DotMulti) last).matchFewest = true; |
1640 |
|
} |
1641 |
4259 |
else if (last instanceof Multi || last instanceof DotMulti |
1642 |
|
|| last instanceof FastMulti) |
1643 |
|
{ |
1644 |
1 |
throw new RegSyntax("Syntax error."); |
1645 |
|
} |
1646 |
4258 |
else if (last2 == null) |
1647 |
|
{ |
1648 |
2623 |
p = mkMulti(i1, i2, p); |
1649 |
|
} |
1650 |
|
else |
1651 |
|
{ |
1652 |
1635 |
last2.next = mkMulti(i1, i2, last); |
1653 |
|
} |
1654 |
|
} |
1655 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 4 |
Complexity Density: 1.33 |
|
1656 |
4258 |
final static Pattern mkMulti(patInt lo, patInt hi, Pattern p)... |
1657 |
|
throws RegSyntax |
1658 |
|
{ |
1659 |
4258 |
if (p instanceof Any && p.next == null) |
1660 |
|
{ |
1661 |
383 |
return new DotMulti(lo, hi); |
1662 |
|
} |
1663 |
3875 |
return RegOpt.safe4fm(p) ? (Pattern) new FastMulti(lo, hi, p) |
1664 |
|
: (Pattern) new Multi(lo, hi, p); |
1665 |
|
} |
1666 |
|
|
1667 |
|
|
|
|
| 47.7% |
Uncovered Elements: 69 (132) |
Complexity: 28 |
Complexity Density: 0.33 |
|
1668 |
2176 |
Pattern matchBracket(StrPos sp) throws RegSyntax... |
1669 |
|
{ |
1670 |
2176 |
Bracket ret; |
1671 |
2176 |
if (sp.match('^')) |
1672 |
|
{ |
1673 |
419 |
ret = new Bracket(true); |
1674 |
419 |
sp.inc(); |
1675 |
|
} |
1676 |
|
else |
1677 |
|
{ |
1678 |
1757 |
ret = new Bracket(false); |
1679 |
|
} |
1680 |
2176 |
if (sp.match(']')) |
1681 |
|
{ |
1682 |
|
|
1683 |
0 |
RegSyntaxError.endItAll("Unmatched []"); |
1684 |
|
} |
1685 |
|
|
1686 |
10293 |
while (!sp.eos && !sp.match(']')) |
1687 |
|
{ |
1688 |
8117 |
StrPos s1 = new StrPos(sp); |
1689 |
8117 |
s1.inc(); |
1690 |
8117 |
StrPos s1_ = new StrPos(s1); |
1691 |
8117 |
s1_.inc(); |
1692 |
8117 |
if (s1.match('-') && !s1_.match(']')) |
1693 |
|
{ |
1694 |
1830 |
StrPos s2 = new StrPos(s1); |
1695 |
1830 |
s2.inc(); |
1696 |
1830 |
if (!s2.eos) |
1697 |
|
{ |
1698 |
1830 |
ret.addOr(new Range(sp.c, s2.c)); |
1699 |
|
} |
1700 |
1830 |
sp.inc(); |
1701 |
1830 |
sp.inc(); |
1702 |
|
} |
1703 |
6287 |
else if (sp.escMatch('Q')) |
1704 |
|
{ |
1705 |
0 |
sp.inc(); |
1706 |
0 |
while (!sp.escMatch('E')) |
1707 |
|
{ |
1708 |
0 |
ret.addOr(new oneChar(sp.c)); |
1709 |
0 |
sp.inc(); |
1710 |
|
} |
1711 |
|
} |
1712 |
6287 |
else if (sp.escMatch('d')) |
1713 |
|
{ |
1714 |
48 |
ret.addOr(new Range('0', '9')); |
1715 |
|
} |
1716 |
6239 |
else if (sp.escMatch('s')) |
1717 |
|
{ |
1718 |
0 |
ret.addOr(new oneChar((char) 32)); |
1719 |
0 |
ret.addOr(new Range((char) 8, (char) 10)); |
1720 |
0 |
ret.addOr(new oneChar((char) 13)); |
1721 |
|
} |
1722 |
6239 |
else if (sp.escMatch('w')) |
1723 |
|
{ |
1724 |
0 |
ret.addOr(new Range('a', 'z')); |
1725 |
0 |
ret.addOr(new Range('A', 'Z')); |
1726 |
0 |
ret.addOr(new Range('0', '9')); |
1727 |
0 |
ret.addOr(new oneChar('_')); |
1728 |
|
} |
1729 |
6239 |
else if (sp.escMatch('D')) |
1730 |
|
{ |
1731 |
0 |
ret.addOr(new Range((char) 0, (char) 47)); |
1732 |
0 |
ret.addOr(new Range((char) 58, (char) 65535)); |
1733 |
|
} |
1734 |
6239 |
else if (sp.escMatch('S')) |
1735 |
|
{ |
1736 |
0 |
ret.addOr(new Range((char) 0, (char) 7)); |
1737 |
0 |
ret.addOr(new Range((char) 11, (char) 12)); |
1738 |
0 |
ret.addOr(new Range((char) 14, (char) 31)); |
1739 |
0 |
ret.addOr(new Range((char) 33, (char) 65535)); |
1740 |
|
} |
1741 |
6239 |
else if (sp.escMatch('W')) |
1742 |
|
{ |
1743 |
0 |
ret.addOr(new Range((char) 0, (char) 64)); |
1744 |
0 |
ret.addOr(new Range((char) 91, (char) 94)); |
1745 |
0 |
ret.addOr(new oneChar((char) 96)); |
1746 |
0 |
ret.addOr(new Range((char) 123, (char) 65535)); |
1747 |
|
} |
1748 |
6239 |
else if (sp.escMatch('x') && next2Hex(sp)) |
1749 |
|
{ |
1750 |
0 |
sp.inc(); |
1751 |
0 |
int d = getHexDigit(sp); |
1752 |
0 |
sp.inc(); |
1753 |
0 |
d = 16 * d + getHexDigit(sp); |
1754 |
0 |
ret.addOr(new oneChar((char) d)); |
1755 |
|
} |
1756 |
6239 |
else if (sp.escMatch('a')) |
1757 |
|
{ |
1758 |
0 |
ret.addOr(new oneChar((char) 7)); |
1759 |
|
} |
1760 |
6239 |
else if (sp.escMatch('f')) |
1761 |
|
{ |
1762 |
0 |
ret.addOr(new oneChar((char) 12)); |
1763 |
|
} |
1764 |
6239 |
else if (sp.escMatch('e')) |
1765 |
|
{ |
1766 |
0 |
ret.addOr(new oneChar((char) 27)); |
1767 |
|
} |
1768 |
6239 |
else if (sp.escMatch('n')) |
1769 |
|
{ |
1770 |
0 |
ret.addOr(new oneChar('\n')); |
1771 |
|
} |
1772 |
6239 |
else if (sp.escMatch('t')) |
1773 |
|
{ |
1774 |
0 |
ret.addOr(new oneChar('\t')); |
1775 |
|
} |
1776 |
6239 |
else if (sp.escMatch('r')) |
1777 |
|
{ |
1778 |
0 |
ret.addOr(new oneChar('\r')); |
1779 |
|
} |
1780 |
6239 |
else if (sp.escMatch('c')) |
1781 |
|
{ |
1782 |
0 |
sp.inc(); |
1783 |
0 |
if (sp.c < Ctrl.cmap.length) |
1784 |
|
{ |
1785 |
0 |
ret.addOr(new oneChar(Ctrl.cmap[sp.c])); |
1786 |
|
} |
1787 |
|
else |
1788 |
|
{ |
1789 |
0 |
ret.addOr(new oneChar(sp.c)); |
1790 |
|
} |
1791 |
|
} |
1792 |
6239 |
else if (isOctalString(sp)) |
1793 |
|
{ |
1794 |
0 |
int d = sp.c - '0'; |
1795 |
0 |
sp.inc(); |
1796 |
0 |
d = 8 * d + sp.c - '0'; |
1797 |
0 |
StrPos sp2 = new StrPos(sp); |
1798 |
0 |
sp2.inc(); |
1799 |
0 |
if (isOctalDigit(sp2, false)) |
1800 |
|
{ |
1801 |
0 |
sp.inc(); |
1802 |
0 |
d = 8 * d + sp.c - '0'; |
1803 |
|
} |
1804 |
0 |
ret.addOr(new oneChar((char) d)); |
1805 |
|
} |
1806 |
|
else |
1807 |
|
{ |
1808 |
6239 |
ret.addOr(new oneChar(sp.c)); |
1809 |
|
} |
1810 |
8117 |
sp.inc(); |
1811 |
|
} |
1812 |
2176 |
return ret; |
1813 |
|
} |
1814 |
|
|
1815 |
|
|
1816 |
|
|
1817 |
|
|
1818 |
|
|
1819 |
|
|
1820 |
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 19 |
Complexity Density: 0.7 |
|
1821 |
0 |
@Override... |
1822 |
|
public String toString() |
1823 |
|
{ |
1824 |
0 |
if (false && thePattern == null) |
1825 |
|
{ |
1826 |
0 |
return ""; |
1827 |
|
} |
1828 |
|
else |
1829 |
|
{ |
1830 |
0 |
StringBuffer sb = new StringBuffer(); |
1831 |
0 |
if (esc != Pattern.ESC) |
1832 |
|
{ |
1833 |
0 |
sb.append("(?e="); |
1834 |
0 |
sb.append(esc); |
1835 |
0 |
sb.append(")"); |
1836 |
|
} |
1837 |
0 |
if (gFlag || mFlag || !dotDoesntMatchCR || sFlag || ignoreCase |
1838 |
|
|| dontMatchInQuotes || optimized()) |
1839 |
|
{ |
1840 |
0 |
sb.append("(?"); |
1841 |
0 |
if (ignoreCase) |
1842 |
|
{ |
1843 |
0 |
sb.append("i"); |
1844 |
|
} |
1845 |
0 |
if (mFlag) |
1846 |
|
{ |
1847 |
0 |
sb.append("m"); |
1848 |
|
} |
1849 |
0 |
if (sFlag || !dotDoesntMatchCR) |
1850 |
|
{ |
1851 |
0 |
sb.append("s"); |
1852 |
|
} |
1853 |
0 |
if (dontMatchInQuotes) |
1854 |
|
{ |
1855 |
0 |
sb.append("Q"); |
1856 |
|
} |
1857 |
0 |
if (optimized()) |
1858 |
|
{ |
1859 |
0 |
sb.append("o"); |
1860 |
|
} |
1861 |
0 |
if (gFlag) |
1862 |
|
{ |
1863 |
0 |
sb.append("g"); |
1864 |
|
} |
1865 |
0 |
sb.append(")"); |
1866 |
|
} |
1867 |
0 |
String patstr = thePattern.toString(); |
1868 |
0 |
if (esc != Pattern.ESC) |
1869 |
|
{ |
1870 |
0 |
patstr = reEscape(patstr, Pattern.ESC, esc); |
1871 |
|
} |
1872 |
0 |
sb.append(patstr); |
1873 |
0 |
return sb.toString(); |
1874 |
|
} |
1875 |
|
} |
1876 |
|
|
1877 |
|
|
1878 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 7 |
Complexity Density: 0.44 |
|
1879 |
0 |
static String reEscape(String s, char oldEsc, char newEsc)... |
1880 |
|
{ |
1881 |
0 |
if (oldEsc == newEsc) |
1882 |
|
{ |
1883 |
0 |
return s; |
1884 |
|
} |
1885 |
0 |
int i; |
1886 |
0 |
StringBuffer sb = new StringBuffer(); |
1887 |
0 |
for (i = 0; i < s.length(); i++) |
1888 |
|
{ |
1889 |
0 |
if (s.charAt(i) == oldEsc && i + 1 < s.length()) |
1890 |
|
{ |
1891 |
0 |
if (s.charAt(i + 1) == oldEsc) |
1892 |
|
{ |
1893 |
0 |
sb.append(oldEsc); |
1894 |
|
} |
1895 |
|
else |
1896 |
|
{ |
1897 |
0 |
sb.append(newEsc); |
1898 |
0 |
sb.append(s.charAt(i + 1)); |
1899 |
|
} |
1900 |
0 |
i++; |
1901 |
|
} |
1902 |
0 |
else if (s.charAt(i) == newEsc) |
1903 |
|
{ |
1904 |
0 |
sb.append(newEsc); |
1905 |
0 |
sb.append(newEsc); |
1906 |
|
} |
1907 |
|
else |
1908 |
|
{ |
1909 |
0 |
sb.append(s.charAt(i)); |
1910 |
|
} |
1911 |
|
} |
1912 |
0 |
return sb.toString(); |
1913 |
|
} |
1914 |
|
|
1915 |
|
|
1916 |
|
|
1917 |
|
|
1918 |
|
|
1919 |
|
|
1920 |
|
@see |
1921 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1922 |
0 |
@Override... |
1923 |
|
public boolean accept(File dir, String s) |
1924 |
|
{ |
1925 |
0 |
return search(s); |
1926 |
|
} |
1927 |
|
|
1928 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1929 |
0 |
final static public String version()... |
1930 |
|
{ |
1931 |
0 |
return "lgpl release 1.5.3"; |
1932 |
|
} |
1933 |
|
|
1934 |
|
|
1935 |
|
|
1936 |
|
|
1937 |
|
|
1938 |
|
|
1939 |
|
|
1940 |
|
|
1941 |
|
|
1942 |
|
|
1943 |
|
|
1944 |
|
|
1945 |
|
|
1946 |
|
|
1947 |
|
|
1948 |
|
|
1949 |
|
|
1950 |
|
|
1951 |
|
|
1952 |
|
@see |
1953 |
|
@see |
1954 |
|
@see |
1955 |
|
@see |
1956 |
|
@see |
1957 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
1958 |
339 |
public void optimize()... |
1959 |
|
{ |
1960 |
339 |
if (optimized() || thePattern == null) |
1961 |
|
{ |
1962 |
0 |
return; |
1963 |
|
} |
1964 |
339 |
minMatch = new patInt(0); |
1965 |
339 |
thePattern = RegOpt.opt(thePattern, ignoreCase, dontMatchInQuotes); |
1966 |
339 |
skipper = Skip.findSkip(this); |
1967 |
|
|
1968 |
339 |
return; |
1969 |
|
} |
1970 |
|
|
1971 |
|
Skip skipper; |
1972 |
|
|
1973 |
|
|
1974 |
|
|
1975 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1976 |
339 |
public boolean optimized()... |
1977 |
|
{ |
1978 |
339 |
return minMatch != null; |
1979 |
|
} |
1980 |
|
|
1981 |
|
|
1982 |
|
|
1983 |
|
|
1984 |
|
|
1985 |
|
|
1986 |
|
|
1987 |
|
|
1988 |
|
|
1989 |
|
|
1990 |
|
|
1991 |
|
|
1992 |
|
|
1993 |
|
|
1994 |
|
|
1995 |
|
|
1996 |
|
|
1997 |
|
|
1998 |
|
|
1999 |
|
|
2000 |
|
|
2001 |
|
|
2002 |
|
|
2003 |
|
|
2004 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2005 |
110 |
public static Regex perlCode(String s)... |
2006 |
|
{ |
2007 |
|
|
2008 |
|
|
2009 |
110 |
return parsePerl.parse(s); |
2010 |
|
} |
2011 |
|
|
2012 |
|
static final char back_slash = '\\'; |
2013 |
|
|
2014 |
|
|
2015 |
|
|
2016 |
|
|
2017 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
2018 |
0 |
public boolean isLiteral()... |
2019 |
|
{ |
2020 |
0 |
Pattern x = thePattern; |
2021 |
0 |
while (x != null) |
2022 |
|
{ |
2023 |
0 |
if (x instanceof oneChar) |
2024 |
|
{ |
2025 |
0 |
; |
2026 |
|
} |
2027 |
0 |
else if (x instanceof Skipped) |
2028 |
|
{ |
2029 |
0 |
; |
2030 |
|
} |
2031 |
|
else |
2032 |
|
{ |
2033 |
0 |
return false; |
2034 |
|
} |
2035 |
0 |
x = x.next; |
2036 |
|
} |
2037 |
0 |
return true; |
2038 |
|
} |
2039 |
|
|
2040 |
|
|
2041 |
|
|
2042 |
|
|
2043 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2044 |
0 |
public patInt countMinChars()... |
2045 |
|
{ |
2046 |
0 |
return thePattern.countMinChars(); |
2047 |
|
} |
2048 |
|
|
2049 |
|
|
2050 |
|
|
2051 |
|
|
2052 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2053 |
0 |
public patInt countMaxChars()... |
2054 |
|
{ |
2055 |
0 |
return thePattern.countMaxChars(); |
2056 |
|
} |
2057 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
2058 |
0 |
boolean isHexDigit(StrPos sp)... |
2059 |
|
{ |
2060 |
0 |
boolean r = !sp.eos && !sp.dontMatch |
2061 |
|
&& ((sp.c >= '0' && sp.c <= '9') || (sp.c >= 'a' && sp.c <= 'f') |
2062 |
|
|| (sp.c >= 'A' && sp.c <= 'F')); |
2063 |
0 |
return r; |
2064 |
|
} |
2065 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
2066 |
17719 |
boolean isOctalDigit(StrPos sp, boolean first)... |
2067 |
|
{ |
2068 |
17719 |
boolean r = !sp.eos && !(first ^ sp.dontMatch) && sp.c >= '0' |
2069 |
|
&& sp.c <= '7'; |
2070 |
17719 |
return r; |
2071 |
|
} |
2072 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
2073 |
0 |
int getHexDigit(StrPos sp)... |
2074 |
|
{ |
2075 |
0 |
if (sp.c >= '0' && sp.c <= '9') |
2076 |
|
{ |
2077 |
0 |
return sp.c - '0'; |
2078 |
|
} |
2079 |
0 |
if (sp.c >= 'a' && sp.c <= 'f') |
2080 |
|
{ |
2081 |
0 |
return sp.c - 'a' + 10; |
2082 |
|
} |
2083 |
0 |
return sp.c - 'A' + 10; |
2084 |
|
} |
2085 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
2086 |
0 |
boolean next2Hex(StrPos sp)... |
2087 |
|
{ |
2088 |
0 |
StrPos sp2 = new StrPos(sp); |
2089 |
0 |
sp2.inc(); |
2090 |
0 |
if (!isHexDigit(sp2)) |
2091 |
|
{ |
2092 |
0 |
return false; |
2093 |
|
} |
2094 |
0 |
sp2.inc(); |
2095 |
0 |
if (!isHexDigit(sp2)) |
2096 |
|
{ |
2097 |
0 |
return false; |
2098 |
|
} |
2099 |
0 |
return true; |
2100 |
|
} |
2101 |
|
|
|
|
| 27.3% |
Uncovered Elements: 8 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
2102 |
17719 |
boolean isOctalString(StrPos sp)... |
2103 |
|
{ |
2104 |
17719 |
if (!isOctalDigit(sp, true)) |
2105 |
|
{ |
2106 |
17719 |
return false; |
2107 |
|
} |
2108 |
0 |
StrPos sp2 = new StrPos(sp); |
2109 |
0 |
sp2.inc(); |
2110 |
0 |
if (!isOctalDigit(sp2, false)) |
2111 |
|
{ |
2112 |
0 |
return false; |
2113 |
|
} |
2114 |
0 |
return true; |
2115 |
|
} |
2116 |
|
} |