Package jodd.util

Class Wildcard

java.lang.Object
jodd.util.Wildcard

public class Wildcard extends Object
Checks whether a string or path matches a given wildcard pattern. Possible patterns allow to match single characters ('?') or any count of characters ('*'). Wildcard characters can be escaped (by an '\'). When matching path, deep tree wildcard also can be used ('**').

This method uses recursive matching, as in linux or windows. regexp works the same. This method is very fast, comparing to similar implementations.

  • Field Details

  • Constructor Details

    • Wildcard

      public Wildcard()
  • Method Details

    • match

      public static boolean match(CharSequence string, CharSequence pattern)
      Checks whether a string matches a given wildcard pattern.
      Parameters:
      string - input string
      pattern - pattern to match
      Returns:
      true if string matches the pattern, otherwise false
    • equalsOrMatch

      public static boolean equalsOrMatch(CharSequence string, CharSequence pattern)
      Checks if two strings are equals or if they match(CharSequence, CharSequence). Useful for cases when matching a lot of equal strings and speed is important.
    • match

      private static boolean match(CharSequence string, CharSequence pattern, int sNdx, int pNdx)
      Internal matching recursive function.
    • matchOne

      public static int matchOne(String src, String... patterns)
      Matches string to at least one pattern. Returns index of matched pattern, or -1 otherwise.
      See Also:
    • matchPathOne

      public static int matchPathOne(String path, String... patterns)
      Matches path to at least one pattern. Returns index of matched pattern or -1 otherwise.
      See Also:
    • matchPath

      public static boolean matchPath(String path, String pattern)
      Matches path against pattern using *, ? and ** wildcards. Both path and the pattern are tokenized on path separators (both \ and /). '**' represents deep tree wildcard, as in Ant.
    • matchTokens

      protected static boolean matchTokens(String[] tokens, String[] patterns)
      Match tokenized string and pattern.