1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.velocity.tools; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
import java.util.regex.Matcher; |
25 |
|
import java.util.regex.Pattern; |
26 |
|
import java.util.regex.PatternSyntaxException; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@version |
32 |
|
@since |
33 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 10 |
Complexity Density: 0.53 |
|
34 |
|
public class RegexTool |
35 |
|
{ |
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
39 |
|
public class RegexResult |
40 |
|
{ |
41 |
|
|
42 |
|
@see |
43 |
|
|
44 |
|
public int start; |
45 |
|
|
46 |
|
|
47 |
|
@see |
48 |
|
|
49 |
|
public int end; |
50 |
|
|
51 |
|
|
52 |
|
@see |
53 |
|
|
54 |
|
public String group; |
55 |
|
|
56 |
|
|
57 |
|
@param@link |
58 |
|
@param@link |
59 |
|
@param@link |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
61 |
227 |
public RegexResult(int start, int end, String group)... |
62 |
|
{ |
63 |
227 |
this.start = start; |
64 |
227 |
this.end = end; |
65 |
227 |
this.group = group; |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
@return |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
113 |
public String getGroup()... |
72 |
|
{ |
73 |
113 |
return this.group; |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
@return |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
11 |
public int getStart()... |
80 |
|
{ |
81 |
11 |
return this.start; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@return |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
20 |
public int getEnd()... |
88 |
|
{ |
89 |
20 |
return this.end; |
90 |
|
} |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
@param |
96 |
|
@return@link |
97 |
|
|
98 |
|
|
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
100 |
110 |
public List<RegexResult> find(String content, String regex)... |
101 |
|
{ |
102 |
110 |
List<RegexResult> result = new ArrayList<RegexResult>(); |
103 |
110 |
Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); |
104 |
110 |
if (matcher.find()) { |
105 |
303 |
for (int i = 0; i < matcher.groupCount() + 1; i++) { |
106 |
221 |
result.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); |
107 |
|
} |
108 |
|
} |
109 |
110 |
return result; |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
@param |
115 |
|
@return@link |
116 |
|
|
117 |
|
|
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
119 |
2 |
public List<List<RegexResult>> findAll(String content, String regex)... |
120 |
|
{ |
121 |
2 |
List<List<RegexResult>> result = new ArrayList<>(); |
122 |
2 |
Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); |
123 |
4 |
while (matcher.find()) { |
124 |
2 |
List<RegexResult> match = new ArrayList<>(); |
125 |
8 |
for (int i = 0; i < matcher.groupCount() + 1; i++) { |
126 |
6 |
match.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); |
127 |
|
} |
128 |
2 |
result.add(match); |
129 |
|
} |
130 |
2 |
return result; |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
@param |
137 |
|
@return |
138 |
|
|
139 |
|
@since |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
141 |
3 |
public Pattern compile(String regex)... |
142 |
|
{ |
143 |
3 |
try { |
144 |
3 |
return Pattern.compile(regex); |
145 |
|
} catch (PatternSyntaxException ex) { |
146 |
1 |
return null; |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
@return |
160 |
|
@since |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
271 |
public String quote(String s)... |
163 |
|
{ |
164 |
271 |
return Pattern.quote(s); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
@param |
175 |
|
@return |
176 |
|
@since |
177 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
178 |
5 |
public String quoteReplacement(String s)... |
179 |
|
{ |
180 |
5 |
return Matcher.quoteReplacement(s); |
181 |
|
} |
182 |
|
} |