KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > regexp > internal > REUtil


1 package com.sun.org.apache.regexp.internal;
2
3 /*
4  * ====================================================================
5  *
6  * The Apache Software License, Version 1.1
7  *
8  * Copyright (c) 1999 The Apache Software Foundation. All rights
9  * reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided with the
21  * distribution.
22  *
23  * 3. The end-user documentation included with the redistribution, if
24  * any, must include the following acknowlegement:
25  * "This product includes software developed by the
26  * Apache Software Foundation (http://www.apache.org/)."
27  * Alternately, this acknowlegement may appear in the software itself,
28  * if and wherever such third-party acknowlegements normally appear.
29  *
30  * 4. The names "The Jakarta Project", "Jakarta-Regexp", and "Apache Software
31  * Foundation" must not be used to endorse or promote products derived
32  * from this software without prior written permission. For written
33  * permission, please contact apache@apache.org.
34  *
35  * 5. Products derived from this software may not be called "Apache"
36  * nor may "Apache" appear in their names without prior written
37  * permission of the Apache Group.
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This software consists of voluntary contributions made by many
54  * individuals on behalf of the Apache Software Foundation. For more
55  * information on the Apache Software Foundation, please see
56  * <http://www.apache.org/>.
57  *
58  */

59
60 /**
61  * This is a class that contains utility helper methods for this package.
62  *
63  * @author <a HREF="mailto:jonl@muppetlabs.com">Jonathan Locke</a>
64  * @version $Id: REUtil.java,v 1.2 2000/04/30 20:42:35 jon Exp $
65  */

66 public class REUtil
67 {
68     /** complex: */
69     private static final String JavaDoc complexPrefix = "complex:";
70     
71     /**
72      * Creates a regular expression, permitting simple or complex syntax
73      * @param expression The expression, beginning with a prefix if it's complex or
74      * having no prefix if it's simple
75      * @param matchFlags Matching style flags
76      * @return The regular expression object
77      * @exception RESyntaxException thrown in case of error
78      */

79     public static RE createRE(String JavaDoc expression, int matchFlags) throws RESyntaxException
80     {
81         if (expression.startsWith(complexPrefix))
82         {
83             return new RE(expression.substring(complexPrefix.length()), matchFlags);
84         }
85         return new RE(RE.simplePatternToFullRegularExpression(expression), matchFlags);
86     }
87
88     /**
89      * Creates a regular expression, permitting simple or complex syntax
90      * @param expression The expression, beginning with a prefix if it's complex or
91      * having no prefix if it's simple
92      * @return The regular expression object
93      * @exception RESyntaxException thrown in case of error
94      */

95     public static RE createRE(String JavaDoc expression) throws RESyntaxException
96     {
97         return createRE(expression, RE.MATCH_NORMAL);
98     }
99 }
100
Popular Tags