Class WildcharMatcher


  • public class WildcharMatcher
    extends 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.
    • Constructor Detail

      • WildcharMatcher

        public WildcharMatcher()
    • Method Detail

      • testSet

        public static boolean testSet​(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​(String pattern,
                                    int ofp,
                                    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​(String pattern,
                                    String str)
        DOCUMENT ME!
        Parameters:
        pattern - DOCUMENT ME!
        str - DOCUMENT ME!
        Returns:
        DOCUMENT ME!