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