DESY ACOP Beans Home

com.cosylab.util
Class WildcharMatcher

java.lang.Object
  extended by com.cosylab.util.WildcharMatcher

public class WildcharMatcher
extends java.lang.Object

A Unix-like wildchar matcher. Supported wild-characters: '', '?'; sets: [a-z], '!' negation Examples: '[a-g]li?n' matches 'florian' '[!abc]e' matches 'smile' '[-z] matches 'a' Rules for sets: RegEx definition of the valid set is: [!]?(-.)?((.-.)|(.))(.-)? a-z : match any letter between 'a' and 'z' inclusively [-a : match everything up to and including 'a' (only valid at beginning) a-] : match everything from 'a' (only valid at the end) a : match exactly 'a' !a : not operator, match everything except 'a' (only allowed at beginning) \a : treat a literally (useful for specifying '!]-' in sets. Note that \t\b\n... are not processed. Wildchar rules: : match any number (0..inf) number of occurences of any character ? : match exactly and only one occurence of any character ab : match exactly 'ab' [..]: same as , but character must match the set.

Version:
$id$
Author:
Ales Pucelj

Constructor Summary
WildcharMatcher()
           
 
Method Summary
static void main(java.lang.String[] args)
          Run test applet.
static boolean match(java.lang.String pattern, java.lang.String str)
          DOCUMENT ME!
static boolean parse(java.lang.String pattern, int ofp, java.lang.String str, int ofs)
          Recursive method for parsing the string.
static boolean testSet(java.lang.String pattern, int offset, char ch)
          DFA for parsing set strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WildcharMatcher

public WildcharMatcher()
Method Detail

testSet

public static boolean testSet(java.lang.String pattern,
                              int offset,
                              char ch)
DFA for parsing set strings. DFA was obtained from JFlex using the rule : macro: CHAR = [^-\]\!] (everything except ], ! and - rule : [!]?(-{CHAR})?(({CHAR}-{CHAR})|({CHAR}))({CHAR}-)?\] Result of optimized NDFA is Character classes: class 0: [0-' ']['"'-',']['.'-'\']['^'-65535] class 1: [']'] class 2: ['!'] class 3: ['-'] Transition graph (for class goto state) State 0: 0 -> 1, 1 -> 2, 2 -> 3, 3 -> 4 State 1: 0 -> 1, 1 -> 2, 3 -> 5 State [FINAL] State 3: 0 -> 1, 1 -> 2, 3 -> 4 State 4: 0 -> 6 State 5: 0 -> 6, 1 -> 2 State 6: 0 -> 1, 1 -> 2

Parameters:
pattern - DOCUMENT ME!
offset - DOCUMENT ME!
ch - DOCUMENT ME!
Returns:
DOCUMENT ME!

parse

public static boolean parse(java.lang.String pattern,
                            int ofp,
                            java.lang.String str,
                            int ofs)
Recursive method for parsing the string. To avoid copying the strings, the method accepts offset indices into both parameters.

Parameters:
pattern - Pattern used in parsing
ofp - Offset into pattern string (ofp > 0)
str - String to test
ofs - Offset into test string (ofs > 0);
Returns:
boolean Do the strings match

match

public static boolean match(java.lang.String pattern,
                            java.lang.String str)
DOCUMENT ME!

Parameters:
pattern - DOCUMENT ME!
str - DOCUMENT ME!
Returns:
DOCUMENT ME!

main

public static void main(java.lang.String[] args)
Run test applet.

Parameters:
args - command line parameters


Copyright © 2010. All Rights Reserved.