File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 22
33import java .util .Collection ;
44import java .util .function .Supplier ;
5+ import java .util .regex .Pattern ;
56
67import static java .lang .String .format ;
78
@@ -100,6 +101,8 @@ public static void assertFalse(boolean condition) {
100101
101102 private static final String invalidNameErrorMessage = "Name must be non-null, non-empty and match [_A-Za-z][_0-9A-Za-z]* - was '%s'" ;
102103
104+ private static final Pattern validNamePattern = Pattern .compile ("[_A-Za-z][_0-9A-Za-z]*" );
105+
103106 /**
104107 * Validates that the Lexical token name matches the current spec.
105108 * currently non null, non empty,
@@ -108,7 +111,7 @@ public static void assertFalse(boolean condition) {
108111 * @return the name if valid, or AssertException if invalid.
109112 */
110113 public static String assertValidName (String name ) {
111- if (name != null && !name .isEmpty () && name .matches ("[_A-Za-z][_0-9A-Za-z]*" )) {
114+ if (name != null && !name .isEmpty () && validNamePattern . matcher ( name ) .matches ()) {
112115 return name ;
113116 }
114117 throw new AssertException (String .format (invalidNameErrorMessage , name ));
You can’t perform that action at this time.
0 commit comments