1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
package com.stevesoft.pat; |
9 |
|
|
10 |
|
import java.util.Hashtable; |
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
|
|
| 41.3% |
Uncovered Elements: 81 (138) |
Complexity: 33 |
Complexity Density: 0.42 |
|
16 |
|
class DotMulti extends PatternSub |
17 |
|
{ |
18 |
|
patInt fewestMatches, mostMatches; |
19 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
20 |
0 |
public patInt minChars()... |
21 |
|
{ |
22 |
0 |
return fewestMatches; |
23 |
|
} |
24 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
25 |
0 |
public patInt maxChars()... |
26 |
|
{ |
27 |
0 |
return mostMatches; |
28 |
|
} |
29 |
|
|
30 |
|
public boolean matchFewest = false; |
31 |
|
|
32 |
|
StringLike src = null; |
33 |
|
|
34 |
|
int srclength = 0; |
35 |
|
|
36 |
|
boolean dotDoesntMatchCR = true; |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
38 |
331 |
DotMulti(patInt a, patInt b)... |
39 |
|
{ |
40 |
331 |
fewestMatches = a; |
41 |
331 |
mostMatches = b; |
42 |
|
} |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
44 |
0 |
public String toString()... |
45 |
|
{ |
46 |
0 |
return ".{" + fewestMatches + "," + mostMatches + "}" |
47 |
0 |
+ (matchFewest ? "?" : "") + "(?# <= dot multi)" + nextString(); |
48 |
|
} |
49 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
50 |
100580 |
final int submatchInternal(int pos, Pthings pt)... |
51 |
|
{ |
52 |
100580 |
if (pos < srclength) |
53 |
|
{ |
54 |
97779 |
if (dotDoesntMatchCR) |
55 |
|
{ |
56 |
97779 |
if (src.charAt(pos) != '\n') |
57 |
|
{ |
58 |
97779 |
return 1 + pos; |
59 |
|
} |
60 |
|
} |
61 |
|
else |
62 |
|
{ |
63 |
0 |
return 1 + pos; |
64 |
|
} |
65 |
|
} |
66 |
2801 |
return -1; |
67 |
|
} |
68 |
|
|
69 |
|
final static int step = 1; |
70 |
|
|
71 |
|
static int idcount = 1; |
72 |
|
|
|
|
| 39.4% |
Uncovered Elements: 66 (109) |
Complexity: 23 |
Complexity Density: 0.35 |
|
73 |
2827 |
public int matchInternal(int pos, Pthings pt)... |
74 |
|
{ |
75 |
2827 |
int m = -1; |
76 |
2827 |
int i = pos; |
77 |
2827 |
src = pt.src; |
78 |
2827 |
srclength = src.length(); |
79 |
2827 |
dotDoesntMatchCR = pt.dotDoesntMatchCR; |
80 |
2827 |
if (matchFewest) |
81 |
|
{ |
82 |
0 |
int nMatches = 0; |
83 |
0 |
while (fewestMatches.intValue() > nMatches) |
84 |
|
{ |
85 |
0 |
i = submatchInternal(i, pt); |
86 |
0 |
if (i < 0) |
87 |
|
{ |
88 |
0 |
return -1; |
89 |
|
} |
90 |
0 |
nMatches++; |
91 |
|
} |
92 |
0 |
if (i < 0) |
93 |
|
{ |
94 |
0 |
return -1; |
95 |
|
} |
96 |
0 |
int ii = nextMatch(i, pt); |
97 |
0 |
if (ii >= 0) |
98 |
|
{ |
99 |
0 |
return ii; |
100 |
|
} |
101 |
0 |
if (!mostMatches.finite()) |
102 |
|
{ |
103 |
0 |
while (i >= 0) |
104 |
|
{ |
105 |
0 |
i = submatchInternal(i, pt); |
106 |
0 |
if (i < 0) |
107 |
|
{ |
108 |
0 |
return -1; |
109 |
|
} |
110 |
0 |
ii = nextMatch(i, pt); |
111 |
0 |
if (ii >= 0) |
112 |
|
{ |
113 |
0 |
return ii; |
114 |
|
} |
115 |
|
} |
116 |
|
} |
117 |
|
else |
118 |
|
{ |
119 |
0 |
while (i > 0) |
120 |
|
{ |
121 |
0 |
i = submatchInternal(i, pt); |
122 |
0 |
if (i < 0) |
123 |
|
{ |
124 |
0 |
return -1; |
125 |
|
} |
126 |
0 |
nMatches++; |
127 |
0 |
if (nMatches > mostMatches.intValue()) |
128 |
|
{ |
129 |
0 |
return -1; |
130 |
|
} |
131 |
0 |
ii = nextMatch(i, pt); |
132 |
0 |
if (ii >= 0) |
133 |
|
{ |
134 |
0 |
return ii; |
135 |
|
} |
136 |
|
} |
137 |
|
} |
138 |
0 |
return -1; |
139 |
|
} |
140 |
2827 |
int nMatches = 0; |
141 |
2827 |
while (fewestMatches.intValue() > nMatches) |
142 |
|
{ |
143 |
0 |
i = submatchInternal(i, pt); |
144 |
0 |
if (i >= 0) |
145 |
|
{ |
146 |
0 |
nMatches++; |
147 |
|
} |
148 |
|
else |
149 |
|
{ |
150 |
0 |
return -1; |
151 |
|
} |
152 |
|
} |
153 |
2827 |
m = i; |
154 |
2827 |
if (mostMatches.finite()) |
155 |
|
{ |
156 |
52 |
while (nMatches < mostMatches.intValue()) |
157 |
|
{ |
158 |
26 |
i = submatchInternal(i, pt); |
159 |
26 |
if (i >= 0) |
160 |
|
{ |
161 |
26 |
m = i; |
162 |
26 |
nMatches++; |
163 |
|
} |
164 |
|
else |
165 |
|
{ |
166 |
0 |
break; |
167 |
|
} |
168 |
|
} |
169 |
|
} |
170 |
|
else |
171 |
|
{ |
172 |
2801 |
while (true) |
173 |
|
{ |
174 |
100554 |
i = submatchInternal(i, pt); |
175 |
100554 |
if (i >= 0) |
176 |
|
{ |
177 |
97753 |
m = i; |
178 |
97753 |
nMatches++; |
179 |
|
} |
180 |
|
else |
181 |
|
{ |
182 |
2801 |
break; |
183 |
|
} |
184 |
|
} |
185 |
|
} |
186 |
2844 |
while (m >= pos) |
187 |
|
{ |
188 |
2844 |
int r = nextMatch(m, pt); |
189 |
2844 |
if (r >= 0) |
190 |
|
{ |
191 |
2823 |
return r; |
192 |
|
} |
193 |
21 |
m -= step; |
194 |
21 |
nMatches--; |
195 |
21 |
if (nMatches < fewestMatches.intValue()) |
196 |
|
{ |
197 |
4 |
return -1; |
198 |
|
} |
199 |
|
} |
200 |
0 |
return -1; |
201 |
|
} |
202 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
203 |
0 |
Pattern clone1(Hashtable h)... |
204 |
|
{ |
205 |
0 |
DotMulti dm = new DotMulti(fewestMatches, mostMatches); |
206 |
0 |
dm.matchFewest = matchFewest; |
207 |
0 |
return dm; |
208 |
|
} |
209 |
|
} |