Class | Line # | Actions | |||
---|---|---|---|---|---|
BackMatch | 15 | 15 | 10 |
1 | // | |
2 | // This software is now distributed according to | |
3 | // the Lesser Gnu Public License. Please see | |
4 | // http://www.gnu.org/copyleft/lesser.txt for | |
5 | // the details. | |
6 | // -- Happy Computing! | |
7 | // | |
8 | package com.stevesoft.pat; | |
9 | ||
10 | import java.util.Hashtable; | |
11 | ||
12 | /** | |
13 | * Provides the ability to match a backreference from within a Pattern. | |
14 | */ | |
15 | class BackMatch extends Pattern | |
16 | { | |
17 | int id; | |
18 | ||
19 | 0 | BackMatch(int id) |
20 | { | |
21 | 0 | this.id = id; |
22 | } | |
23 | ||
24 | 0 | public String toString() |
25 | { | |
26 | 0 | return "\\" + (id) + nextString(); |
27 | } | |
28 | ||
29 | 0 | public int matchInternal(int pos, Pthings p) |
30 | { | |
31 | 0 | int i1 = p.marks[id]; |
32 | 0 | int i2 = p.marks[id + p.nMarks]; |
33 | 0 | int imax = i2 - i1; |
34 | 0 | if (i1 < 0 || imax < 0 || pos + imax > p.src.length()) |
35 | { | |
36 | 0 | return -1; |
37 | } | |
38 | 0 | int ns = p.src.length() - pos; |
39 | 0 | if (imax < ns) |
40 | { | |
41 | 0 | ns = imax; |
42 | } | |
43 | 0 | for (int i = 0; i < ns; i++) |
44 | { | |
45 | 0 | if (p.src.charAt(i + i1) != p.src.charAt(pos + i)) |
46 | { | |
47 | 0 | return -1; |
48 | } | |
49 | } | |
50 | 0 | return nextMatch(pos + imax, p); |
51 | } | |
52 | ||
53 | 0 | Pattern clone1(Hashtable h) |
54 | { | |
55 | 0 | return new BackMatch(id); |
56 | } | |
57 | } |