2 * gnu/regexp/UncheckedRE.java
3 * Copyright (C) 2001 Wes Biggs
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; either version 2.1 of the License, or
8 * (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * UncheckedRE is a subclass of RE that allows programmers an easier means
24 * of programmatically precompiling regular expressions. It is constructed
25 * and used in exactly the same manner as an instance of the RE class; the
26 * only difference is that its constructors do not throw REException.
27 * Instead, if a syntax error is encountered during construction, a
28 * RuntimeException will be thrown.
30 * Note that this makes UncheckedRE dangerous if constructed with
31 * dynamic data. Do not use UncheckedRE unless you are completely sure
32 * that all input being passed to it contains valid, well-formed
33 * regular expressions for the syntax specified.
35 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
37 * @since gnu.regexp 1.1.4
40 public final class UncheckedRE extends RE {
42 * Constructs a regular expression pattern buffer without any compilation
43 * flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5).
45 * @param pattern A regular expression pattern, in the form of a String,
46 * StringBuffer or char[]. Other input types will be converted to
47 * strings using the toString() method.
48 * @exception RuntimeException The input pattern could not be parsed.
49 * @exception NullPointerException The pattern was null.
51 public UncheckedRE(Object pattern) {
52 this(pattern,0,RESyntax.RE_SYNTAX_PERL5);
56 * Constructs a regular expression pattern buffer using the specified
57 * compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5).
59 * @param pattern A regular expression pattern, in the form of a String,
60 * StringBuffer, or char[]. Other input types will be converted to
61 * strings using the toString() method.
62 * @param cflags The logical OR of any combination of the compilation flags in the RE class.
63 * @exception RuntimeException The input pattern could not be parsed.
64 * @exception NullPointerException The pattern was null.
66 public UncheckedRE(Object pattern, int cflags) {
67 this(pattern,cflags,RESyntax.RE_SYNTAX_PERL5);
71 * Constructs a regular expression pattern buffer using the specified
72 * compilation flags and regular expression syntax.
74 * @param pattern A regular expression pattern, in the form of a String,
75 * StringBuffer, or char[]. Other input types will be converted to
76 * strings using the toString() method.
77 * @param cflags The logical OR of any combination of the compilation flags in the RE class.
78 * @param syntax The type of regular expression syntax to use.
79 * @exception RuntimeException The input pattern could not be parsed.
80 * @exception NullPointerException The pattern was null.
82 public UncheckedRE(Object pattern, int cflags, RESyntax syntax) {
84 initialize(pattern,cflags,syntax,0,0);
85 } catch (REException e) {
86 throw new RuntimeException(e.getMessage());