|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| RegExpCreator.java | - | 100% | 50% | 75% |
|
||||||||||||||
| 1 | /* $Id: RegExpCreator.java,v 1.1 2004/03/18 15:21:54 johndavidtaylor Exp $ | |
| 2 | * Created on Mar 10, 2004 by jdt | |
| 3 | * The alipes project | |
| 4 | * (c) 2004 | |
| 5 | * | |
| 6 | */ | |
| 7 | package org.abraracourcix.alipes.common; | |
| 8 | ||
| 9 | /** | |
| 10 | * This class generates regular expressions from simple wildcard expressions. | |
| 11 | * For this class, wildcard expressions are expressions of the form | |
| 12 | * "a*.txt" to match "a.txt, ab.txt..... | |
| 13 | * or | |
| 14 | * "abc.???" to match "abc.abc, abc.txt2 but not "abc.text" | |
| 15 | * @author jdt | |
| 16 | */ | |
| 17 | public final class RegExpCreator { | |
| 18 | /** | |
| 19 | * | |
| 20 | * Constructor to hide public ctor | |
| 21 | * | |
| 22 | */ | |
| 23 | 0 | private RegExpCreator(){} |
| 24 | /** | |
| 25 | * Given a wildcard expression return the corresponding regexp | |
| 26 | * @param wildcard the wildcard | |
| 27 | * @return the regexp | |
| 28 | */ | |
| 29 | 6 | public static String getRegExp(final String wildcard) { |
| 30 | //Probably inefficient due to use of strings | |
| 31 | //Want to make the transformations .->\. | |
| 32 | // *-> .* | |
| 33 | // ?-> . | |
| 34 | // Complicated syntax due to need to escape chars, and fact that first arg in | |
| 35 | // replaceAll is itself a regexp | |
| 36 | 6 | String regexp = wildcard.replaceAll("\\.","\\\\.").replace('?','.').replaceAll("\\*",".*"); |
| 37 | 6 | return regexp; |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | ||
| 42 | /* | |
| 43 | * $Log: RegExpCreator.java,v $ | |
| 44 | * Revision 1.1 2004/03/18 15:21:54 johndavidtaylor | |
| 45 | * Copied across from incubation in beanpeeler | |
| 46 | * | |
| 47 | * Revision 1.1 2004/03/11 09:49:24 johndavidtaylor | |
| 48 | * Loads of updates | |
| 49 | * | |
| 50 | */ |
|
||||||||||