10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.runtime.regexp;
27
28 import jdk.nashorn.internal.parser.Lexer;
29 import jdk.nashorn.internal.runtime.ParserException;
30
31 /**
32 * Factory class for regular expressions. This class creates instances of {@link DefaultRegExp}.
33 */
34 public class RegExpFactory {
35
36
37 private final static RegExpFactory instance = new RegExpFactory();
38
39 /**
40 * Creates a Regular expression from the given {@code pattern} and {@code flags} strings.
41 *
42 * @param pattern RegExp pattern string
43 * @param flags RegExp flags string
44 * @throws ParserException if flags is invalid or pattern string has syntax error.
45 */
46 protected RegExp compile(final String pattern, final String flags) throws ParserException {
47 return new DefaultRegExp(pattern, flags);
48 }
49
50 /**
51 * Replace a regexp token as suitable for regexp instances created by this factory.
52 *
53 * @param str a regular expression token
54 * @return the replacement token
55 */
56 protected String replaceToken(final String str) {
57 switch (str) {
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.runtime.regexp;
27
28 import jdk.nashorn.internal.parser.Lexer;
29 import jdk.nashorn.internal.runtime.ParserException;
30 import jdk.nashorn.internal.runtime.options.Options;
31
32 /**
33 * Factory class for regular expressions. This class creates instances of {@link DefaultRegExp}.
34 * An alternative factory can be installed using the {@code nashorn.regexp.impl} system property.
35 */
36 public class RegExpFactory {
37
38
39 private final static RegExpFactory instance;
40
41 private final static String JDK = "jdk";
42 private final static String JONI = "joni";
43
44 static {
45 final String impl = Options.getStringProperty("nashorn.regexp.impl", JDK);
46 switch (impl) {
47 case JONI:
48 instance = new JoniRegExp.Factory();
49 break;
50 case JDK:
51 instance = new RegExpFactory();
52 break;
53 default:
54 instance = null;
55 throw new InternalError("Unsupported RegExp factory: " + impl);
56 }
57 }
58
59 /**
60 * Creates a Regular expression from the given {@code pattern} and {@code flags} strings.
61 *
62 * @param pattern RegExp pattern string
63 * @param flags RegExp flags string
64 * @throws ParserException if flags is invalid or pattern string has syntax error.
65 */
66 protected RegExp compile(final String pattern, final String flags) throws ParserException {
67 return new DefaultRegExp(pattern, flags);
68 }
69
70 /**
71 * Replace a regexp token as suitable for regexp instances created by this factory.
72 *
73 * @param str a regular expression token
74 * @return the replacement token
75 */
76 protected String replaceToken(final String str) {
77 switch (str) {
|