src/jdk/nashorn/internal/runtime/regexp/RegExpFactory.java
Print this page
*** 25,42 ****
package jdk.nashorn.internal.runtime.regexp;
import jdk.nashorn.internal.parser.Lexer;
import jdk.nashorn.internal.runtime.ParserException;
/**
* Factory class for regular expressions. This class creates instances of {@link DefaultRegExp}.
*/
public class RegExpFactory {
! private final static RegExpFactory instance = new RegExpFactory();
/**
* Creates a Regular expression from the given {@code pattern} and {@code flags} strings.
*
* @param pattern RegExp pattern string
--- 25,62 ----
package jdk.nashorn.internal.runtime.regexp;
import jdk.nashorn.internal.parser.Lexer;
import jdk.nashorn.internal.runtime.ParserException;
+ import jdk.nashorn.internal.runtime.options.Options;
/**
* Factory class for regular expressions. This class creates instances of {@link DefaultRegExp}.
+ * An alternative factory can be installed using the {@code nashorn.regexp.impl} system property.
*/
public class RegExpFactory {
! private final static RegExpFactory instance;
!
! private final static String JDK = "jdk";
! private final static String JONI = "joni";
!
! static {
! final String impl = Options.getStringProperty("nashorn.regexp.impl", JDK);
! switch (impl) {
! case JONI:
! instance = new JoniRegExp.Factory();
! break;
! case JDK:
! instance = new RegExpFactory();
! break;
! default:
! instance = null;
! throw new InternalError("Unsupported RegExp factory: " + impl);
! }
! }
/**
* Creates a Regular expression from the given {@code pattern} and {@code flags} strings.
*
* @param pattern RegExp pattern string