1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
package com.stevesoft.pat; |
9 |
|
|
10 |
|
import jalview.util.MessageManager; |
11 |
|
|
12 |
|
import com.stevesoft.pat.wrap.StringWrap; |
13 |
|
|
14 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
15 |
|
class RegHolder |
16 |
|
{ |
17 |
|
Regex me = null; |
18 |
|
|
19 |
|
RegHolder prev = null; |
20 |
|
} |
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
@see |
26 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
27 |
|
class CodeVal |
28 |
|
{ |
29 |
|
int pos; |
30 |
|
|
31 |
|
char code; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
33 |
0 |
CodeVal(int p, char c)... |
34 |
|
{ |
35 |
0 |
pos = p; |
36 |
0 |
code = c; |
37 |
|
} |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
0 |
public String toString()... |
40 |
|
{ |
41 |
0 |
return "(" + pos + "," + code + ")"; |
42 |
|
} |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@see |
56 |
|
@see |
57 |
|
|
|
|
| 37.8% |
Uncovered Elements: 115 (185) |
Complexity: 59 |
Complexity Density: 0.55 |
|
58 |
|
public class Replacer |
59 |
|
{ |
60 |
|
boolean first; |
61 |
|
|
62 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
63 |
18 |
public Replacer()... |
64 |
|
{ |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
public StringLike replaceFirstRegion(String s, Regex r, int start,... |
68 |
|
int end) |
69 |
|
{ |
70 |
0 |
return replaceFirstRegion(new StringWrap(s), r, start, end); |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
77 |
0 |
public StringLike replaceFirstRegion(StringLike s, Regex r, int start,... |
78 |
|
int end) |
79 |
|
{ |
80 |
0 |
first = true; |
81 |
0 |
rh.me = r; |
82 |
0 |
rh.prev = null; |
83 |
0 |
return dorep(s, start, end); |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0 |
public StringLike replaceFirst(StringLike s)... |
87 |
|
{ |
88 |
0 |
return replaceFirstRegion(s, 0, s.length()); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
public StringLike replaceFirstFrom(StringLike s, int start)... |
92 |
|
{ |
93 |
0 |
return replaceFirstRegion(s, start, s.length()); |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
96 |
0 |
public StringLike replaceFirstRegion(StringLike s, int start, int end)... |
97 |
|
{ |
98 |
0 |
first = true; |
99 |
0 |
return dorep(s, start, end); |
100 |
|
} |
101 |
|
|
102 |
|
RegHolder rh = new RegHolder(); |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
152 |
public StringLike replaceAllRegion(String s, Regex r, int start, int end)... |
105 |
|
{ |
106 |
152 |
return replaceAllRegion(new StringWrap(s), r, start, end); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
113 |
152 |
public StringLike replaceAllRegion(StringLike s, Regex r, int start,... |
114 |
|
int end) |
115 |
|
{ |
116 |
152 |
first = false; |
117 |
|
|
118 |
152 |
rh.me = r; |
119 |
152 |
rh.prev = null; |
120 |
152 |
return dorep(s, start, end); |
121 |
|
} |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
0 |
public StringLike replaceAll(StringLike s)... |
124 |
|
{ |
125 |
0 |
return replaceAllRegion(s, 0, s.length()); |
126 |
|
} |
127 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
0 |
public StringLike replaceAllFrom(StringLike s, int start)... |
129 |
|
{ |
130 |
0 |
return replaceAllRegion(s, start, s.length()); |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
133 |
0 |
public StringLike replaceAllRegion(StringLike s, int start, int end)... |
134 |
|
{ |
135 |
0 |
first = false; |
136 |
0 |
return dorep(s, start, end); |
137 |
|
} |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
139 |
0 |
public String replaceAll(String s)... |
140 |
|
{ |
141 |
0 |
return replaceAllRegion(new StringWrap(s), 0, s.length()).toString(); |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
144 |
0 |
public String replaceAllFrom(String s, int start)... |
145 |
|
{ |
146 |
0 |
return replaceAllRegion(new StringWrap(s), start, s.length()) |
147 |
|
.toString(); |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
150 |
0 |
public String replaceAllRegion(String s, int start, int end)... |
151 |
|
{ |
152 |
0 |
first = false; |
153 |
0 |
return dorep(new StringWrap(s), start, end).toString(); |
154 |
|
} |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
156 |
0 |
final public boolean isSpecial(ReplaceRule x)... |
157 |
|
{ |
158 |
0 |
while (x != null) |
159 |
|
{ |
160 |
0 |
if (x instanceof SpecialRule || (x instanceof RuleHolder |
161 |
|
&& ((RuleHolder) x).held instanceof SpecialRule)) |
162 |
|
{ |
163 |
0 |
return true; |
164 |
|
} |
165 |
0 |
x = x.next; |
166 |
|
} |
167 |
0 |
return false; |
168 |
|
} |
169 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
170 |
0 |
final public void apply1(RegRes rr)... |
171 |
|
{ |
172 |
0 |
rr.charsMatched_++; |
173 |
0 |
apply(rr, null); |
174 |
0 |
rr.charsMatched_--; |
175 |
|
} |
176 |
|
|
|
|
| 52.6% |
Uncovered Elements: 18 (38) |
Complexity: 11 |
Complexity Density: 0.5 |
|
177 |
152 |
final StringLike dorep(StringLike s, int start, int end)... |
178 |
|
{ |
179 |
152 |
StringLike ret = s; |
180 |
152 |
want_more_text = false; |
181 |
152 |
lastMatchedTo = 0; |
182 |
152 |
if (rh.me == null) |
183 |
|
{ |
184 |
0 |
throw new NullPointerException(MessageManager |
185 |
|
.getString("exception.replace_null_regex_pointer")); |
186 |
|
} |
187 |
152 |
if (rh.me._search(s, start, end)) |
188 |
|
{ |
189 |
3 |
int rmn = rh.me.matchedTo(); |
190 |
3 |
if (rh.me.charsMatched() == 0 && !isSpecial(rh.me.getReplaceRule())) |
191 |
|
{ |
192 |
0 |
apply1(rh.me); |
193 |
0 |
rmn++; |
194 |
|
} |
195 |
3 |
apply(rh.me); |
196 |
3 |
if (!first) |
197 |
|
{ |
198 |
3 |
for (int i = rmn; !want_more_text |
199 |
|
&& rh.me._search(s, i, end); i = rmn) |
200 |
|
{ |
201 |
0 |
rmn = rh.me.matchedTo(); |
202 |
0 |
if (rh.me.charsMatched() == 0) |
203 |
|
{ |
204 |
0 |
if (!isSpecial(rh.me.getReplaceRule())) |
205 |
|
{ |
206 |
0 |
apply1(rh.me); |
207 |
|
} |
208 |
0 |
rmn++; |
209 |
|
} |
210 |
0 |
apply(rh.me); |
211 |
|
} |
212 |
|
} |
213 |
3 |
ret = finish(); |
214 |
3 |
ret = ret == null ? s : ret; |
215 |
|
} |
216 |
152 |
return ret; |
217 |
|
} |
218 |
|
|
219 |
|
StringBufferLike sb = null; |
220 |
|
|
221 |
|
StringLike src = null; |
222 |
|
|
223 |
|
int pos = 0; |
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
|
|
| 45.3% |
Uncovered Elements: 29 (53) |
Complexity: 17 |
Complexity Density: 0.63 |
|
232 |
3 |
public void apply(RegRes r, ReplaceRule rp)... |
233 |
|
{ |
234 |
3 |
if (rp == null || (rp.next == null && rp instanceof AmpersandRule)) |
235 |
|
{ |
236 |
0 |
return; |
237 |
|
} |
238 |
3 |
if (r.didMatch()) |
239 |
|
{ |
240 |
3 |
if (src == null) |
241 |
|
{ |
242 |
3 |
src = r.getStringLike(); |
243 |
|
} |
244 |
3 |
if (sb == null) |
245 |
|
{ |
246 |
3 |
sb = new StringBufferLike(src.newStringBufferLike()); |
247 |
|
} |
248 |
3 |
int rmf = r.matchedFrom(); |
249 |
72 |
for (int ii = pos; ii < rmf; ii++) |
250 |
|
{ |
251 |
69 |
sb.append(src.charAt(ii)); |
252 |
|
} |
253 |
|
|
254 |
6 |
for (ReplaceRule x = rp; x != null; x = x.next) |
255 |
|
{ |
256 |
3 |
x.apply(sb, r); |
257 |
3 |
if (x instanceof SpecialRule) |
258 |
|
{ |
259 |
0 |
if (x instanceof WantMoreTextReplaceRule && want_more_text_enable) |
260 |
|
{ |
261 |
0 |
want_more_text = true; |
262 |
|
} |
263 |
0 |
else if (x instanceof PushRule) |
264 |
|
{ |
265 |
0 |
RegHolder rh2 = new RegHolder(); |
266 |
0 |
rh2.me = ((PushRule) x).NewRule; |
267 |
0 |
rh2.prev = rh; |
268 |
0 |
rh = rh2; |
269 |
|
} |
270 |
0 |
else if (x instanceof PopRule) |
271 |
|
{ |
272 |
0 |
if (rh.prev != null) |
273 |
|
{ |
274 |
0 |
rh = rh.prev; |
275 |
|
} |
276 |
|
} |
277 |
0 |
else if (x instanceof ChangeRule) |
278 |
|
{ |
279 |
0 |
rh.me = ((ChangeRule) x).NewRule; |
280 |
|
} |
281 |
|
} |
282 |
|
} |
283 |
3 |
if (!want_more_text) |
284 |
|
{ |
285 |
3 |
pos = r.matchedTo(); |
286 |
|
} |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
boolean want_more_text = false, want_more_text_enable = false; |
291 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
292 |
0 |
public boolean WantMoreText()... |
293 |
|
{ |
294 |
0 |
return want_more_text; |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
300 |
3 |
public void apply(Regex r)... |
301 |
|
{ |
302 |
3 |
apply(r, r.getReplaceRule()); |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
|
|
| 86.7% |
Uncovered Elements: 2 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
311 |
3 |
public StringLike finish()... |
312 |
|
{ |
313 |
3 |
if (src == null) |
314 |
|
{ |
315 |
0 |
return null; |
316 |
|
} |
317 |
|
|
318 |
3 |
int s_end = src.length(); |
319 |
60 |
for (int ii = pos; ii < s_end; ii++) |
320 |
|
{ |
321 |
57 |
sb.append(src.charAt(ii)); |
322 |
|
} |
323 |
3 |
src = null; |
324 |
3 |
lastMatchedTo = pos; |
325 |
3 |
pos = 0; |
326 |
3 |
StringLike retstr = sb.toStringLike(); |
327 |
3 |
sb = null; |
328 |
3 |
return retstr; |
329 |
|
} |
330 |
|
|
331 |
|
int lastMatchedTo = 0; |
332 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
333 |
0 |
public Object clone()... |
334 |
|
{ |
335 |
0 |
Replacer r = new Replacer(); |
336 |
0 |
r.first = first; |
337 |
0 |
r.src = src; |
338 |
0 |
r.sb = sb; |
339 |
0 |
r.pos = pos; |
340 |
0 |
r.lastMatchedTo = lastMatchedTo; |
341 |
0 |
r.want_more_text = want_more_text; |
342 |
0 |
r.want_more_text_enable = want_more_text_enable; |
343 |
0 |
r.rh.me = rh.me; |
344 |
0 |
r.rh.prev = rh.prev; |
345 |
0 |
return r; |
346 |
|
} |
347 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
348 |
0 |
public int lastMatchedTo()... |
349 |
|
{ |
350 |
0 |
return lastMatchedTo; |
351 |
|
} |
352 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
353 |
0 |
public Regex getRegex()... |
354 |
|
{ |
355 |
0 |
return rh.me; |
356 |
|
} |
357 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
358 |
0 |
public void setSource(StringLike sl)... |
359 |
|
{ |
360 |
0 |
src = sl; |
361 |
|
} |
362 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
363 |
0 |
public void setBuffer(StringBufferLike sbl)... |
364 |
|
{ |
365 |
0 |
sb = sbl; |
366 |
|
} |
367 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
368 |
0 |
public void setPos(int pos)... |
369 |
|
{ |
370 |
0 |
this.pos = pos; |
371 |
|
} |
372 |
|
} |