|
1 | 1 | package com.laytonsmith.core.functions; |
2 | 2 |
|
3 | | -import com.laytonsmith.PureUtilities.Common.ReflectionUtils; |
4 | 3 | import com.laytonsmith.annotations.api; |
5 | 4 | import com.laytonsmith.annotations.core; |
6 | 5 | import com.laytonsmith.annotations.seealso; |
@@ -44,8 +43,7 @@ public static String docs() { |
44 | 43 | + "[[Regex|regular expressions]]. Note that all the functions are just passthroughs" |
45 | 44 | + " to the Java regex mechanism. If you need to set a flag on the regex, where the api calls" |
46 | 45 | + " for a pattern, instead send array('pattern', 'flags') where flags is any of i, m, or s." |
47 | | - + " Alternatively, using the embedded flag system that Java provides is also valid. Named captures are" |
48 | | - + " also supported if you are using Java 7, otherwise they are not supported."; |
| 46 | + + " Alternatively, using the embedded flag system that Java provides is also valid."; |
49 | 47 | } |
50 | 48 |
|
51 | 49 | @api |
@@ -104,15 +102,8 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime |
104 | 102 | ret.set(i, new CString(m.group(i), t), t); |
105 | 103 | } |
106 | 104 | } |
107 | | - //Named groups are only supported in Java 7, but we can |
108 | | - //dynamically enable this feature if they have it. |
109 | | - Set<String> namedGroups = getNamedGroups(pattern.pattern()); |
110 | | - try { |
111 | | - for(String key : namedGroups) { |
112 | | - ret.set(key, (String) ReflectionUtils.invokeMethod(Matcher.class, m, "group", new Class[]{String.class}, new Object[]{key}), t); |
113 | | - } |
114 | | - } catch (ReflectionUtils.ReflectionException ex) { |
115 | | - throw new CREFormatException("Named captures are only supported with Java 7.", t); |
| 105 | + for(String key : getNamedGroups(pattern.pattern())) { |
| 106 | + ret.set(key, m.group(key), t); |
116 | 107 | } |
117 | 108 | } |
118 | 109 | return ret; |
@@ -143,10 +134,9 @@ public Set<OptimizationOption> optimizationOptions() { |
143 | 134 | public ExampleScript[] examples() throws ConfigCompileException { |
144 | 135 | return new ExampleScript[]{ |
145 | 136 | new ExampleScript("Basic usage", "reg_match('(\\\\d)(\\\\d)(\\\\d)', 'abc123')"), |
146 | | - //Java 7 can't be assumed to be working on the system running the doc gen, so we'll hardcode these. |
147 | | - new ExampleScript("Named captures (Only works if your system is running Java 7)", |
| 137 | + new ExampleScript("Named captures ", |
148 | 138 | "reg_match('abc(?<foo>\\\\d+)(xyz)', 'abc123xyz')", "{0: abc123xyz, 1: 123, 2: xyz, foo: 123}"), |
149 | | - new ExampleScript("Named captures with backreferences (Only works if your system is running Java 7)", |
| 139 | + new ExampleScript("Named captures with backreferences", |
150 | 140 | "reg_match('abc(?<foo>\\\\d+)def\\\\k<foo>', 'abc123def123')['foo']", "123") |
151 | 141 | }; |
152 | 142 | } |
@@ -206,14 +196,8 @@ public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntime |
206 | 196 | for(int i = 1; i <= m.groupCount(); i++) { |
207 | 197 | ret.set(i, new CString(m.group(i), t), t); |
208 | 198 | } |
209 | | - //Named groups are only supported in Java 7, but we can |
210 | | - //dynamically enable this feature if they have it. |
211 | | - try { |
212 | | - for(String key : namedGroups) { |
213 | | - ret.set(key, (String) ReflectionUtils.invokeMethod(Matcher.class, m, "group", new Class[]{String.class}, new Object[]{key}), t); |
214 | | - } |
215 | | - } catch (ReflectionUtils.ReflectionException e) { |
216 | | - throw new CREFormatException("Named captures are only supported with Java 7.", t); |
| 199 | + for(String key : namedGroups) { |
| 200 | + ret.set(key, m.group(key), t); |
217 | 201 | } |
218 | 202 | fret.push(ret, t); |
219 | 203 | } |
@@ -245,10 +229,9 @@ public Set<OptimizationOption> optimizationOptions() { |
245 | 229 | public ExampleScript[] examples() throws ConfigCompileException { |
246 | 230 | return new ExampleScript[]{ |
247 | 231 | new ExampleScript("Basic usage", "reg_match_all('(\\\\d{3})', 'abc123456')"), |
248 | | - //Same thing here, can't guarantee we're running Java 7 when these are generated. |
249 | | - new ExampleScript("Named captures (Only works if your system is running Java 7)", |
| 232 | + new ExampleScript("Named captures", |
250 | 233 | "reg_match_all('abc(?<foo>\\\\d+)(xyz)', 'abc123xyz')[0]['foo']", "123"), |
251 | | - new ExampleScript("Named captures with backreferences (Only works if your system is running Java 7)", |
| 234 | + new ExampleScript("Named captures with backreferences", |
252 | 235 | "reg_match_all('abc(?<foo>\\\\d+)def\\\\k<foo>', 'abc123def123')[0]['foo']", "123") |
253 | 236 | }; |
254 | 237 | } |
@@ -354,7 +337,7 @@ public ExampleScript[] examples() throws ConfigCompileException { |
354 | 337 | return new ExampleScript[]{ |
355 | 338 | new ExampleScript("Basic usage", "reg_replace('\\\\d', 'Z', '123abc')"), |
356 | 339 | new ExampleScript("Using backreferences", "reg_replace('abc(\\\\d+)', '$1', 'abc123')"), |
357 | | - new ExampleScript("Using backreferences with named captures (Only works if your system is running Java 7)", |
| 340 | + new ExampleScript("Using backreferences with named captures", |
358 | 341 | "reg_replace('abc(?<foo>\\\\d+)', '${foo}', 'abc123')", "123") |
359 | 342 | }; |
360 | 343 | } |
|
0 commit comments