KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > regexp > UncheckedRE


1 /*
2  * gnu/regexp/UncheckedRE.java
3  * Copyright (C) 2001 Wes Biggs
4  *
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.
9  *
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.
14  *
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.
18  */

19
20 package gnu.regexp;
21
22 /**
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.
29  * <P>
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.
34  *
35  * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
36  * @see gnu.regexp.RE
37  * @since gnu.regexp 1.1.4
38  */

39
40 public final class UncheckedRE extends RE {
41   /**
42    * Constructs a regular expression pattern buffer without any compilation
43    * flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5).
44    *
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.
50    */

51   public UncheckedRE(Object JavaDoc pattern) {
52       this(pattern,0,RESyntax.RE_SYNTAX_PERL5);
53   }
54
55   /**
56    * Constructs a regular expression pattern buffer using the specified
57    * compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5).
58    *
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.
65    */

66   public UncheckedRE(Object JavaDoc pattern, int cflags) {
67       this(pattern,cflags,RESyntax.RE_SYNTAX_PERL5);
68   }
69
70   /**
71    * Constructs a regular expression pattern buffer using the specified
72    * compilation flags and regular expression syntax.
73    *
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.
81    */

82   public UncheckedRE(Object JavaDoc pattern, int cflags, RESyntax syntax) {
83       try {
84       initialize(pattern,cflags,syntax,0,0);
85       } catch (REException e) {
86       throw new RuntimeException JavaDoc(e.getMessage());
87       }
88   }
89 }
90
91
92
Popular Tags