1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
package com.stevesoft.pat; |
9 |
|
|
10 |
|
import java.util.Enumeration; |
11 |
|
import java.util.Vector; |
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
|
|
| 0% |
Uncovered Elements: 73 (73) |
Complexity: 20 |
Complexity Density: 0.43 |
|
24 |
|
public class RegexTokenizer implements Enumeration |
25 |
|
{ |
26 |
|
String toParse; |
27 |
|
|
28 |
|
Regex r; |
29 |
|
|
30 |
|
int count = 0; |
31 |
|
|
32 |
|
Vector v = new Vector(); |
33 |
|
|
34 |
|
Vector vi = new Vector(); |
35 |
|
|
36 |
|
int pos = 0; |
37 |
|
|
38 |
|
int offset = 1; |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
40 |
0 |
void getMore()... |
41 |
|
{ |
42 |
0 |
String s = r.right(); |
43 |
0 |
if (r.searchFrom(toParse, pos)) |
44 |
|
{ |
45 |
0 |
v.addElement(r.left().substring(pos)); |
46 |
0 |
vi.addElement(Integer.valueOf(r.matchFrom() + r.charsMatched())); |
47 |
0 |
for (int i = 0; i < r.numSubs(); i++) |
48 |
|
{ |
49 |
0 |
if (r.substring() != null) |
50 |
|
{ |
51 |
0 |
v.addElement(r.substring(i + offset)); |
52 |
0 |
vi.addElement(Integer.valueOf( |
53 |
|
r.matchFrom(i + offset) + r.charsMatched(i + offset))); |
54 |
|
} |
55 |
|
} |
56 |
0 |
pos = r.matchFrom() + r.charsMatched(); |
57 |
|
} |
58 |
0 |
else if (s != null) |
59 |
|
{ |
60 |
0 |
v.addElement(s); |
61 |
|
} |
62 |
|
} |
63 |
|
|
64 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
65 |
0 |
public RegexTokenizer(String txt, String ptrn)... |
66 |
|
{ |
67 |
0 |
toParse = txt; |
68 |
0 |
r = new Regex(ptrn); |
69 |
0 |
offset = Regex.BackRefOffset; |
70 |
0 |
getMore(); |
71 |
|
} |
72 |
|
|
73 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
74 |
0 |
public RegexTokenizer(String txt, Regex r)... |
75 |
|
{ |
76 |
0 |
toParse = txt; |
77 |
0 |
this.r = r; |
78 |
0 |
offset = Regex.BackRefOffset; |
79 |
0 |
getMore(); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
86 |
0 |
public Object nextElement()... |
87 |
|
{ |
88 |
0 |
if (count >= v.size()) |
89 |
|
{ |
90 |
0 |
getMore(); |
91 |
|
} |
92 |
0 |
return v.elementAt(count++); |
93 |
|
} |
94 |
|
|
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0 |
public String nextToken()... |
97 |
|
{ |
98 |
0 |
return (String) nextElement(); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
105 |
0 |
public String nextToken(String newpat)... |
106 |
|
{ |
107 |
0 |
try |
108 |
|
{ |
109 |
0 |
r.compile(newpat); |
110 |
|
} catch (RegSyntax r_) |
111 |
|
{ |
112 |
|
} |
113 |
0 |
return nextToken(r); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
120 |
0 |
public String nextToken(Regex nr)... |
121 |
|
{ |
122 |
0 |
r = nr; |
123 |
0 |
if (vi.size() > count) |
124 |
|
{ |
125 |
0 |
pos = ((Integer) vi.elementAt(count)).intValue(); |
126 |
0 |
v.setSize(count); |
127 |
0 |
vi.setSize(count); |
128 |
|
} |
129 |
0 |
getMore(); |
130 |
0 |
return nextToken(); |
131 |
|
} |
132 |
|
|
133 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
134 |
0 |
public boolean hasMoreElements()... |
135 |
|
{ |
136 |
0 |
if (count >= v.size()) |
137 |
|
{ |
138 |
0 |
getMore(); |
139 |
|
} |
140 |
0 |
return count < v.size(); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
0 |
public boolean hasMoreTokens()... |
148 |
|
{ |
149 |
0 |
return hasMoreElements(); |
150 |
|
} |
151 |
|
|
152 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
153 |
0 |
public int countTokens()... |
154 |
|
{ |
155 |
0 |
int _count = count; |
156 |
0 |
while (hasMoreTokens()) |
157 |
|
{ |
158 |
0 |
nextToken(); |
159 |
|
} |
160 |
0 |
count = _count; |
161 |
0 |
return v.size() - count; |
162 |
|
} |
163 |
|
|
164 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
165 |
0 |
public String[] allTokens()... |
166 |
|
{ |
167 |
0 |
countTokens(); |
168 |
0 |
String[] ret = new String[v.size()]; |
169 |
0 |
v.copyInto(ret); |
170 |
0 |
return ret; |
171 |
|
} |
172 |
|
}; |