001/* 002 * gnu/regexp/UncheckedRE.java 003 * Copyright (C) 2001 Wes Biggs 004 * 005 * This library is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published 007 * by the Free Software Foundation; either version 2.1 of the License, or 008 * (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 018 */ 019 020package gnu.regexp; 021 022/** 023 * UncheckedRE is a subclass of RE that allows programmers an easier means 024 * of programmatically precompiling regular expressions. It is constructed 025 * and used in exactly the same manner as an instance of the RE class; the 026 * only difference is that its constructors do not throw REException. 027 * Instead, if a syntax error is encountered during construction, a 028 * RuntimeException will be thrown. 029 * <P> 030 * Note that this makes UncheckedRE dangerous if constructed with 031 * dynamic data. Do not use UncheckedRE unless you are completely sure 032 * that all input being passed to it contains valid, well-formed 033 * regular expressions for the syntax specified. 034 * 035 * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A> 036 * @see gnu.regexp.RE 037 * @since gnu.regexp 1.1.4 038 */ 039 040public final class UncheckedRE extends RE { 041 /** 042 * Constructs a regular expression pattern buffer without any compilation 043 * flags set, and using the default syntax (RESyntax.RE_SYNTAX_PERL5). 044 * 045 * @param pattern A regular expression pattern, in the form of a String, 046 * StringBuffer or char[]. Other input types will be converted to 047 * strings using the toString() method. 048 * @exception RuntimeException The input pattern could not be parsed. 049 * @exception NullPointerException The pattern was null. 050 */ 051 public UncheckedRE(Object pattern) { 052 this(pattern,0,RESyntax.RE_SYNTAX_PERL5); 053 } 054 055 /** 056 * Constructs a regular expression pattern buffer using the specified 057 * compilation flags and the default syntax (RESyntax.RE_SYNTAX_PERL5). 058 * 059 * @param pattern A regular expression pattern, in the form of a String, 060 * StringBuffer, or char[]. Other input types will be converted to 061 * strings using the toString() method. 062 * @param cflags The logical OR of any combination of the compilation flags in the RE class. 063 * @exception RuntimeException The input pattern could not be parsed. 064 * @exception NullPointerException The pattern was null. 065 */ 066 public UncheckedRE(Object pattern, int cflags) { 067 this(pattern,cflags,RESyntax.RE_SYNTAX_PERL5); 068 } 069 070 /** 071 * Constructs a regular expression pattern buffer using the specified 072 * compilation flags and regular expression syntax. 073 * 074 * @param pattern A regular expression pattern, in the form of a String, 075 * StringBuffer, or char[]. Other input types will be converted to 076 * strings using the toString() method. 077 * @param cflags The logical OR of any combination of the compilation flags in the RE class. 078 * @param syntax The type of regular expression syntax to use. 079 * @exception RuntimeException The input pattern could not be parsed. 080 * @exception NullPointerException The pattern was null. 081 */ 082 public UncheckedRE(Object pattern, int cflags, RESyntax syntax) { 083 try { 084 initialize(pattern,cflags,syntax,0,0); 085 } catch (REException e) { 086 throw new RuntimeException(e.getMessage()); 087 } 088 } 089} 090 091