This class provides services for checking strings against string-patterns.
Currently it supports the wildcards
'' for any number of any character and
'?' for any one character. The API is very simple:
There are only the two class methods match() and
matchIgnoreCase().
Example:
StringPattern.match( 'Hello World", "H W" ) ; --> evaluates to true
StringPattern.matchIgnoreCase( 'StringPattern", "str???pat" ) ; -->
evaluates to true
StringPattern
public StringPattern(String pattern)
Initializes the new instance with the string pattern. The default is
case sensitive checking.
pattern
- The pattern to check against ( May contain '' and '?'
wildcards )
StringPattern
public StringPattern(String pattern,
boolean ignoreCase)
Initializes the new instance with the string pattern and the selecteion,
if case should be ignored when comparing characters.
pattern
- The pattern to check against ( May contain '' and '?'
wildcards )ignoreCase
- Definition, if case sensitive character comparison or
not.
StringPattern
public StringPattern(String pattern,
boolean ignoreCase,
char digitWildcard)
Initializes the new instance with the string pattern and the selecteion,
if case should be ignored when comparing characters plus a wildcard
character for digits.
pattern
- The pattern to check against ( May contain '' and '?'
wildcards )ignoreCase
- Definition, if case sensitive character comparison or
not.digitWildcard
- A wildcard character that stands as placeholder for
digits
StringPattern
public StringPattern(String pattern,
char digitWildcard)
Initializes the new instance with the string pattern and a digit
wildcard character. The default is case sensitive checking.
pattern
- The pattern to check against ( May contain '', '?'
wildcards and the digit wildcard )digitWildcard
- A wildcard character that stands as placeholder for
digits
charsAreEqual
protected boolean charsAreEqual(char probeChar,
char patternChar)
digitWildcard
protected Character digitWildcard()
digitWildcard
protected void digitWildcard(Character newValue)
digitWildcardChar
protected char digitWildcardChar()
endNotReached
protected boolean endNotReached(char character)
endReached
protected boolean endReached(char character)
getIgnoreCase
public boolean getIgnoreCase()
Returns whether or not the pattern matching ignores upper and lower case
getPattern
public String getPattern()
Returns the pattern as string.
getPatternChar
protected char getPatternChar(StringExaminer patternIterator,
char probeCh)
hasDigitWildcard
protected boolean hasDigitWildcard()
hasWildcard
public boolean hasWildcard()
Returns true if the pattern contains any '' or '?' wildcard character.
match
public static boolean match(String probe,
String pattern)
Returns true, if the given probe string matches the given pattern.
The character comparison is done case sensitive.
probe
- The string to check against the pattern.pattern
- The patter, that probably contains wildcards ( '' or '?'
)
matchIgnoreCase
public static boolean matchIgnoreCase(String probe,
String pattern)
Returns true, if the given probe string matches the given pattern.
The character comparison is done ignoring upper/lower-case.
probe
- The string to check against the pattern.pattern
- The patter, that probably contains wildcards ( '' or '?'
)
matchReverse
protected boolean matchReverse(String pattern,
StringExaminer probeIterator)
matches
public boolean matches(String probe)
Tests if a specified string matches the pattern.
probe
- The string to compare to the pattern
- true if and only if the probe matches the pattern, false
otherwise.
setDigitWildcardChar
public void setDigitWildcardChar(char digitWildcard)
Sets the given character as a wildcard character in this pattern to
match only digits ('0'-'9').
digitWildcard
- The placeholder character for digits
setIgnoreCase
public void setIgnoreCase(boolean newValue)
Sets whether the pattern matching should ignore case or not
setPattern
public void setPattern(String newValue)
Sets the pattern to a new value
skipAfter
protected boolean skipAfter(StringExaminer examiner,
String matchString)
Increments the given iterator up to the last character that matched the
character sequence in the given matchString. Returns true, if the
matchString was found, otherwise false.
examiner
- matchString
- The string to be found (must not contain )
skipWildcards
protected char skipWildcards(StringExaminer iterator)
Moves the iterator position to the next character that is no wildcard.
Doesn't skip digit wildcards !
toString
public String toString()
Returns the pattern string.
java.lang.Object.toString()