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 |
|
|
15 |
|
|
16 |
|
|
17 |
|
@see |
18 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
19 |
|
class TransRepRule extends ReplaceRule |
20 |
|
{ |
21 |
|
Transformer t; |
22 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
23 |
0 |
TransRepRule(Transformer t)... |
24 |
|
{ |
25 |
0 |
this.t = t; |
26 |
|
} |
27 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
28 |
0 |
public String toString1()... |
29 |
|
{ |
30 |
0 |
return ""; |
31 |
|
} |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
33 |
0 |
public Object clone1()... |
34 |
|
{ |
35 |
0 |
return new TransRepRule(t); |
36 |
|
} |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0 |
public void apply(StringBufferLike sb, RegRes rr)... |
39 |
|
{ |
40 |
|
|
41 |
0 |
next = t.tp.ra[t.tp.pn].getReplaceRule(); |
42 |
|
} |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 79 (79) |
Complexity: 27 |
Complexity Density: 0.64 |
|
63 |
|
public class Transformer |
64 |
|
{ |
65 |
|
TransPat tp; |
66 |
|
|
67 |
|
Regex rp = new Regex(); |
68 |
|
|
69 |
|
boolean auto_optimize; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@see |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
public Replacer getReplacer()... |
77 |
|
{ |
78 |
0 |
return rp.getReplacer(); |
79 |
|
} |
80 |
|
|
81 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
82 |
0 |
public Transformer(boolean auto)... |
83 |
|
{ |
84 |
0 |
auto_optimize = auto; |
85 |
0 |
tp = new TransPat(); |
86 |
0 |
rp.setReplaceRule(new TransRepRule(this)); |
87 |
0 |
rp.thePattern = tp; |
88 |
|
} |
89 |
|
|
90 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
91 |
0 |
public void add(Regex r)... |
92 |
|
{ |
93 |
0 |
if (auto_optimize) |
94 |
|
{ |
95 |
0 |
r.optimize(); |
96 |
|
} |
97 |
0 |
tp.ra[tp.ra_len++] = r; |
98 |
0 |
if (tp.ra.length == tp.ra_len) |
99 |
|
{ |
100 |
0 |
Regex[] ra2 = new Regex[tp.ra_len + 10]; |
101 |
0 |
for (int i = 0; i < tp.ra_len; i++) |
102 |
|
{ |
103 |
0 |
ra2[i] = tp.ra[i]; |
104 |
|
} |
105 |
0 |
tp.ra = ra2; |
106 |
|
} |
107 |
0 |
rp.numSubs_ = r.numSubs_ > rp.numSubs_ ? r.numSubs_ : rp.numSubs_; |
108 |
|
} |
109 |
|
|
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0 |
public int patterns()... |
112 |
|
{ |
113 |
0 |
return tp.ra_len; |
114 |
|
} |
115 |
|
|
116 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
117 |
0 |
public Regex getRegexAt(int i)... |
118 |
|
{ |
119 |
0 |
if (i >= tp.ra_len) |
120 |
|
{ |
121 |
0 |
throw new ArrayIndexOutOfBoundsException("i=" + i + ">=" + patterns()); |
122 |
|
} |
123 |
0 |
if (i < 0) |
124 |
|
{ |
125 |
0 |
throw new ArrayIndexOutOfBoundsException("i=" + i + "< 0"); |
126 |
|
} |
127 |
0 |
return tp.ra[i]; |
128 |
|
} |
129 |
|
|
130 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
131 |
0 |
public void setRegexAt(Regex rx, int i)... |
132 |
|
{ |
133 |
0 |
if (i >= tp.ra_len) |
134 |
|
{ |
135 |
0 |
throw new ArrayIndexOutOfBoundsException("i=" + i + ">=" + patterns()); |
136 |
|
} |
137 |
0 |
if (i < 0) |
138 |
|
{ |
139 |
0 |
throw new ArrayIndexOutOfBoundsException("i=" + i + "< 0"); |
140 |
|
} |
141 |
0 |
tp.ra[i] = rx; |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
@see |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
149 |
0 |
public void add(String rs)... |
150 |
|
{ |
151 |
0 |
Regex r = Regex.perlCode(rs); |
152 |
0 |
if (r == null) |
153 |
|
{ |
154 |
0 |
throw new NullPointerException(MessageManager.formatMessage( |
155 |
|
"exception.bad_pattern_to_regex_perl_code", |
156 |
|
new String[] { rs })); |
157 |
|
} |
158 |
0 |
add(r); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
@see |
166 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
167 |
0 |
public void add(String[] array)... |
168 |
|
{ |
169 |
0 |
for (int i = 0; i < array.length; i++) |
170 |
|
{ |
171 |
0 |
add(array[i]); |
172 |
|
} |
173 |
|
} |
174 |
|
|
175 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
0 |
public String replaceAll(String s)... |
177 |
|
{ |
178 |
0 |
return dorep(s, 0, s.length()); |
179 |
|
} |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
181 |
0 |
public StringLike replaceAll(StringLike s)... |
182 |
|
{ |
183 |
0 |
return dorep(s, 0, s.length()); |
184 |
|
} |
185 |
|
|
186 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
0 |
public String replaceAllFrom(String s, int start)... |
188 |
|
{ |
189 |
0 |
return dorep(s, start, s.length()); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
0 |
public String replaceAllRegion(String s, int start, int end)... |
197 |
|
{ |
198 |
0 |
return dorep(s, start, end); |
199 |
|
} |
200 |
|
|
201 |
|
Replacer repr = new Replacer(); |
202 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
203 |
0 |
final StringLike dorep(StringLike s, int start, int end)... |
204 |
|
{ |
205 |
0 |
StringLike tfmd = repr.replaceAllRegion(s, rp, start, end); |
206 |
0 |
tp.lastMatchedTo = repr.lastMatchedTo; |
207 |
0 |
return tfmd; |
208 |
|
} |
209 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
0 |
final String dorep(String s, int start, int end)... |
211 |
|
{ |
212 |
0 |
return dorep(new StringWrap(s), start, end).toString(); |
213 |
|
} |
214 |
|
|
215 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
0 |
public String replaceFirst(String s)... |
217 |
|
{ |
218 |
0 |
return dorep(s, 0, s.length()); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
224 |
0 |
public String replaceFirstFrom(String s, int start)... |
225 |
|
{ |
226 |
0 |
return dorep(s, start, s.length()); |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
233 |
0 |
public String replaceFirstRegion(String s, int start, int end)... |
234 |
|
{ |
235 |
0 |
return dorep(s, start, end); |
236 |
|
} |
237 |
|
} |