org.metastatic.rsync.v2
Class FNMatch

java.lang.Object
  |
  +--org.metastatic.rsync.v2.FNMatch

public class FNMatch
extends Object

Handles wildcards for filename matching.

I haven't tested this very thoroughly. I blindly replaced all the '/' characters in the code with File.separatorChar. I tried to rework the logic for C-language tests for '\0' correctly.

I would be eager to receive any bug reports at kevinr@gjt.org.

Ported to Java by Kevin Raulerson
JOS CommandLineGroup

Since:
1.0

Field Summary
static int FNM_CASEFOLD
          Compare without regard to case.
static int FNM_FILE_NAME
          Preferred GNU name.
static int FNM_LEADING_DIR
          Ignore `/...' after a match.
static boolean FNM_MATCH
          Value returned by fnmatch() if STRING matches PATTERN.
static int FNM_NOESCAPE
          Backslashes don't quote special chars.
static boolean FNM_NOMATCH
          Value returned by fnmatch() if STRING does not match PATTERN.
static int FNM_PATHNAME
          No wildcard can ever match `/'.
static int FNM_PERIOD
          Leading `.' is matched only explicitly.
 
Constructor Summary
FNMatch()
           
 
Method Summary
static boolean fnmatch(String pattern, String string, int flags)
          Match STRING against the filename pattern PATTERN, returning FNM_MATCH if it matches, FNM_NOMATCH if not.
protected static char fold(char c, int flags)
          If flags has its FNM_CASEFOLD bit set, then returns the lowercase of c; otherwise returns c.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FNM_PATHNAME

public static final int FNM_PATHNAME
No wildcard can ever match `/'. A constant for bits set in the FLAGS argument to fnmatch().

See Also:
Constant Field Values

FNM_NOESCAPE

public static final int FNM_NOESCAPE
Backslashes don't quote special chars. A constant for bits set in the FLAGS argument to fnmatch().

See Also:
Constant Field Values

FNM_PERIOD

public static final int FNM_PERIOD
Leading `.' is matched only explicitly. A constant for bits set in the FLAGS argument to fnmatch().

See Also:
Constant Field Values

FNM_FILE_NAME

public static final int FNM_FILE_NAME
Preferred GNU name. A constant for bits set in the FLAGS argument to fnmatch().

See Also:
Constant Field Values

FNM_LEADING_DIR

public static final int FNM_LEADING_DIR
Ignore `/...' after a match. A constant for bits set in the FLAGS argument to fnmatch().

See Also:
Constant Field Values

FNM_CASEFOLD

public static final int FNM_CASEFOLD
Compare without regard to case. A constant for bits set in the FLAGS argument to fnmatch().

See Also:
Constant Field Values

FNM_NOMATCH

public static final boolean FNM_NOMATCH
Value returned by fnmatch() if STRING does not match PATTERN.

See Also:
Constant Field Values

FNM_MATCH

public static final boolean FNM_MATCH
Value returned by fnmatch() if STRING matches PATTERN.

See Also:
Constant Field Values
Constructor Detail

FNMatch

public FNMatch()
Method Detail

fnmatch

public static boolean fnmatch(String pattern,
                              String string,
                              int flags)
Match STRING against the filename pattern PATTERN, returning FNM_MATCH if it matches, FNM_NOMATCH if not.

Parameters:
pattern - A string with a wildcard (* . ? [ ], etc.; \ is the escape).
string - The string to check for wildcards.
flags - Behavior modifiers.
Returns:
Constant int value FNM_MATCH or FNM_NOMATCH.

fold

protected static char fold(char c,
                           int flags)
If flags has its FNM_CASEFOLD bit set, then returns the lowercase of c; otherwise returns c.

Parameters:
c - A character to fold.
flags - Bits, set or not, to modify behavior.
Returns:
A `folded' character.