mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-16 21:35:25 +00:00
8009240: RegExpScanner code is inefficient and too complex
Reviewed-by: jlaskey, lagergren
This commit is contained in:
parent
66c2fc6e66
commit
bd2109d3fa
@ -117,10 +117,6 @@ public class JoniRegExp extends RegExp {
|
||||
return new JoniRegExp(pattern, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String replaceToken(final String str) {
|
||||
return str.equals("[^]") ? "[\\s\\S]" : str;
|
||||
}
|
||||
}
|
||||
|
||||
class JoniMatcher implements RegExpMatcher {
|
||||
|
||||
@ -67,25 +67,6 @@ public class RegExpFactory {
|
||||
return new DefaultRegExp(pattern, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a regexp token as suitable for regexp instances created by this factory.
|
||||
*
|
||||
* @param str a regular expression token
|
||||
* @return the replacement token
|
||||
*/
|
||||
protected String replaceToken(final String str) {
|
||||
switch (str) {
|
||||
case "\\s":
|
||||
return "[" + Lexer.getWhitespaceRegExp() + "]";
|
||||
case "\\S":
|
||||
return "[^" + Lexer.getWhitespaceRegExp() + "]";
|
||||
case "[^]":
|
||||
return "[\\s\\S]";
|
||||
default:
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a regexp with the given {@code source} and {@code flags}.
|
||||
*
|
||||
@ -98,16 +79,6 @@ public class RegExpFactory {
|
||||
return instance.compile(pattern, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a regexp token as needed by the currently installed factory instance.
|
||||
*
|
||||
* @param token a regexp token
|
||||
* @return the replacement token
|
||||
*/
|
||||
public static String replace(final String token) {
|
||||
return instance.replaceToken(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a regexp with the given {@code source} and {@code flags}.
|
||||
*
|
||||
@ -120,4 +91,13 @@ public class RegExpFactory {
|
||||
public static void validate(final String pattern, final String flags) throws ParserException {
|
||||
instance.compile(pattern, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the instance uses the JDK's {@code java.util.regex} package.
|
||||
*
|
||||
* @return true if instance uses JDK regex package
|
||||
*/
|
||||
public static boolean usesJavaUtilRegex() {
|
||||
return instance != null && instance.getClass() == RegExpFactory.class;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user