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( |
122 |
|
"i=" + i + ">=" + patterns()); |
123 |
|
} |
124 |
0 |
if (i < 0) |
125 |
|
{ |
126 |
0 |
throw new ArrayIndexOutOfBoundsException("i=" + i + "< 0"); |
127 |
|
} |
128 |
0 |
return tp.ra[i]; |
129 |
|
} |
130 |
|
|
131 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
132 |
0 |
public void setRegexAt(Regex rx, int i)... |
133 |
|
{ |
134 |
0 |
if (i >= tp.ra_len) |
135 |
|
{ |
136 |
0 |
throw new ArrayIndexOutOfBoundsException( |
137 |
|
"i=" + i + ">=" + patterns()); |
138 |
|
} |
139 |
0 |
if (i < 0) |
140 |
|
{ |
141 |
0 |
throw new ArrayIndexOutOfBoundsException("i=" + i + "< 0"); |
142 |
|
} |
143 |
0 |
tp.ra[i] = rx; |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
@see |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
151 |
0 |
public void add(String rs)... |
152 |
|
{ |
153 |
0 |
Regex r = Regex.perlCode(rs); |
154 |
0 |
if (r == null) |
155 |
|
{ |
156 |
0 |
throw new NullPointerException(MessageManager.formatMessage( |
157 |
|
"exception.bad_pattern_to_regex_perl_code", new String[] |
158 |
|
{ rs })); |
159 |
|
} |
160 |
0 |
add(r); |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
@see |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
169 |
0 |
public void add(String[] array)... |
170 |
|
{ |
171 |
0 |
for (int i = 0; i < array.length; i++) |
172 |
|
{ |
173 |
0 |
add(array[i]); |
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
0 |
public String replaceAll(String s)... |
179 |
|
{ |
180 |
0 |
return dorep(s, 0, s.length()); |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
183 |
0 |
public StringLike replaceAll(StringLike s)... |
184 |
|
{ |
185 |
0 |
return dorep(s, 0, s.length()); |
186 |
|
} |
187 |
|
|
188 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
0 |
public String replaceAllFrom(String s, int start)... |
190 |
|
{ |
191 |
0 |
return dorep(s, start, s.length()); |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
0 |
public String replaceAllRegion(String s, int start, int end)... |
199 |
|
{ |
200 |
0 |
return dorep(s, start, end); |
201 |
|
} |
202 |
|
|
203 |
|
Replacer repr = new Replacer(); |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
205 |
0 |
final StringLike dorep(StringLike s, int start, int end)... |
206 |
|
{ |
207 |
0 |
StringLike tfmd = repr.replaceAllRegion(s, rp, start, end); |
208 |
0 |
tp.lastMatchedTo = repr.lastMatchedTo; |
209 |
0 |
return tfmd; |
210 |
|
} |
211 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
0 |
final String dorep(String s, int start, int end)... |
213 |
|
{ |
214 |
0 |
return dorep(new StringWrap(s), start, end).toString(); |
215 |
|
} |
216 |
|
|
217 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
0 |
public String replaceFirst(String s)... |
219 |
|
{ |
220 |
0 |
return dorep(s, 0, s.length()); |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
0 |
public String replaceFirstFrom(String s, int start)... |
227 |
|
{ |
228 |
0 |
return dorep(s, start, s.length()); |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
0 |
public String replaceFirstRegion(String s, int start, int end)... |
236 |
|
{ |
237 |
0 |
return dorep(s, start, end); |
238 |
|
} |
239 |
|
} |