File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed
metafix/src/main/java/org/metafacture/metafix Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 22
22
import java .util .Arrays ;
23
23
import java .util .HashMap ;
24
24
import java .util .Map ;
25
+ import java .util .regex .Pattern ;
26
+ import java .util .stream .Collectors ;
25
27
26
28
/**
27
29
* Our goal here is something like https://metacpan.org/pod/Catmandu::Path::simple
33
35
*/
34
36
/*package-private*/ class FixPath {
35
37
38
+ /*package-private*/ static final Pattern RESERVED_FIELD_PATTERN = Pattern .compile (String .format ("(?:%s)" ,
39
+ Arrays .stream (ReservedField .values ()).map (f -> Pattern .quote (f .name ())).collect (Collectors .joining ("|" ))));
36
40
private static final String ASTERISK = "*" ;
37
41
private String [] path ;
38
42
@@ -299,7 +303,7 @@ private String[] tail(final String[] fields) {
299
303
return Arrays .copyOfRange (fields , 1 , fields .length );
300
304
}
301
305
302
- /*package- private*/ enum ReservedField {
306
+ private enum ReservedField {
303
307
$append , $first , $last ;
304
308
305
309
private static final Map <String , ReservedField > STRING_TO_ENUM = new HashMap <>();
Original file line number Diff line number Diff line change 17
17
package org .metafacture .metafix ;
18
18
19
19
import org .metafacture .commons .tries .SimpleRegexTrie ;
20
- import org .metafacture .metafix .FixPath .ReservedField ;
21
20
22
21
import java .util .ArrayList ;
23
22
import java .util .Collection ;
@@ -209,10 +208,7 @@ public Value asList(final Consumer<Array> consumer) {
209
208
210
209
/*package-private*/ Value updatePathRename (final String newName ) {
211
210
if (path != null ) {
212
- final String basePath = split (path )[0 ];
213
- for (final ReservedField rf : ReservedField .values ()) {
214
- path = newName .replace (rf .name (), basePath );
215
- }
211
+ path = FixPath .RESERVED_FIELD_PATTERN .matcher (newName ).replaceAll (Matcher .quoteReplacement (split (path )[0 ]));
216
212
}
217
213
return this ;
218
214
}
You can’t perform that action at this time.
0 commit comments