KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > util > FileNameMatcher


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.util;
22
23 import proguard.classfile.ClassConstants;
24
25 import java.io.*;
26
27 /**
28  * This StringMatcher tests whether file names match a given regular
29  * expression.
30  * Supported wildcards are
31  * '?' for a single regular file name character,
32  * '*' for any number of regular file name characters, and
33  * '**' for any number of regular file name characters or directory separator
34  * characters (always including '/').
35  *
36  * @author Eric Lafortune
37  */

38 public class FileNameMatcher extends BasicMatcher
39 {
40     private static final char[] FILE_NAME_CHARACTERS = new char[]
41     {
42         ' ',
43         '-',
44         '+',
45         '.'
46     };
47
48     private static final char[] EXTENDED_FILE_NAME_CHARACTERS = new char[]
49     {
50         ClassConstants.INTERNAL_PACKAGE_SEPARATOR,
51         File.separatorChar
52     };
53
54
55     /**
56      * Creates a new FileNameMatcher.
57      * @param regularExpression the regular expression against which strings
58      * will be matched.
59      */

60     public FileNameMatcher(String JavaDoc regularExpression)
61     {
62         super(regularExpression,
63               FILE_NAME_CHARACTERS,
64               EXTENDED_FILE_NAME_CHARACTERS,
65               null);
66     }
67
68
69     /**
70      * A main method for testing file name matching.
71      */

72     public static void main(String JavaDoc[] args)
73     {
74         try
75         {
76             System.out.println("Regular expression ["+args[0]+"]");
77             FileNameMatcher matcher = new FileNameMatcher(args[0]);
78             for (int index = 1; index < args.length; index++)
79             {
80                 String JavaDoc string = args[index];
81                 System.out.print("String ["+string+"]");
82                 System.out.println(" -> match = "+matcher.matches(args[index]));
83             }
84         }
85         catch (Exception JavaDoc ex)
86         {
87             ex.printStackTrace();
88         }
89     }
90 }
91
Popular Tags