|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.pf.text.StringPattern
public class StringPattern
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
Field Summary | |
---|---|
protected static java.lang.String |
MULTI_WILDCARD
|
protected static char |
MULTICHAR_WILDCARD
|
protected static char |
SINGLECHAR_WILDCARD
|
Constructor Summary | |
---|---|
StringPattern(java.lang.String pattern)
Initializes the new instance with the string pattern. |
|
StringPattern(java.lang.String pattern,
boolean ignoreCase)
Initializes the new instance with the string pattern and the selecteion, if case should be ignored when comparing characters. |
|
StringPattern(java.lang.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. |
|
StringPattern(java.lang.String pattern,
char digitWildcard)
Initializes the new instance with the string pattern and a digit wildcard character. |
Method Summary | |
---|---|
protected boolean |
charsAreEqual(char probeChar,
char patternChar)
|
protected java.lang.Character |
digitWildcard()
|
protected void |
digitWildcard(java.lang.Character newValue)
|
protected char |
digitWildcardChar()
|
protected boolean |
endNotReached(char character)
|
protected boolean |
endReached(char character)
|
boolean |
getIgnoreCase()
Returns whether or not the pattern matching ignores upper and lower case |
java.lang.String |
getPattern()
Returns the pattern as string. |
protected char |
getPatternChar(StringExaminer patternIterator,
char probeCh)
|
protected boolean |
hasDigitWildcard()
|
boolean |
hasWildcard()
Returns true if the pattern contains any '*' or '?' wildcard character. |
static boolean |
match(java.lang.String probe,
java.lang.String pattern)
Returns true, if the given probe string matches the given pattern. |
boolean |
matches(java.lang.String probe)
Tests if a specified string matches the pattern. |
static boolean |
matchIgnoreCase(java.lang.String probe,
java.lang.String pattern)
Returns true, if the given probe string matches the given pattern. |
protected boolean |
matchReverse(java.lang.String pattern,
StringExaminer probeIterator)
|
protected StringExaminer |
newExaminer(java.lang.String str)
|
void |
setDigitWildcardChar(char digitWildcard)
Sets the given character as a wildcard character in this pattern to match only digits ('0'-'9'). |
void |
setIgnoreCase(boolean newValue)
Sets whether the pattern matching should ignore case or not |
void |
setPattern(java.lang.String newValue)
Sets the pattern to a new value |
protected boolean |
skipAfter(StringExaminer examiner,
java.lang.String matchString)
Increments the given iterator up to the last character that matched the character sequence in the given matchString. |
protected char |
skipWildcards(StringExaminer iterator)
Moves the iterator position to the next character that is no wildcard. |
protected StringUtil |
strUtil()
|
java.lang.String |
toString()
Returns the pattern string. |
protected java.lang.String |
upToEnd(StringExaminer iterator)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String MULTI_WILDCARD
protected static final char MULTICHAR_WILDCARD
protected static final char SINGLECHAR_WILDCARD
Constructor Detail |
---|
public StringPattern(java.lang.String pattern, boolean ignoreCase)
pattern
- The pattern to check against ( May contain '*' and '?' wildcards )ignoreCase
- Definition, if case sensitive character comparison or not.public StringPattern(java.lang.String pattern)
pattern
- The pattern to check against ( May contain '*' and '?' wildcards )public StringPattern(java.lang.String pattern, char digitWildcard)
pattern
- The pattern to check against ( May contain '*', '?' wildcards and the digit wildcard )digitWildcard
- A wildcard character that stands as placeholder for digitspublic StringPattern(java.lang.String pattern, boolean ignoreCase, char digitWildcard)
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 digitsMethod Detail |
---|
public boolean getIgnoreCase()
public void setIgnoreCase(boolean newValue)
public java.lang.String getPattern()
public void setPattern(java.lang.String newValue)
protected java.lang.Character digitWildcard()
protected void digitWildcard(java.lang.Character newValue)
public static boolean match(java.lang.String probe, java.lang.String pattern)
probe
- The string to check against the pattern.pattern
- The patter, that probably contains wildcards ( '*' or '?' )public static boolean matchIgnoreCase(java.lang.String probe, java.lang.String pattern)
probe
- The string to check against the pattern.pattern
- The patter, that probably contains wildcards ( '*' or '?' )public boolean matches(java.lang.String probe)
probe
- The string to compare to the pattern
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public boolean hasWildcard()
public void setDigitWildcardChar(char digitWildcard)
digitWildcard
- The placeholder character for digitsprotected boolean hasDigitWildcard()
protected char digitWildcardChar()
protected char skipWildcards(StringExaminer iterator)
protected boolean skipAfter(StringExaminer examiner, java.lang.String matchString)
matchString
- The string to be found (must not contain *)protected java.lang.String upToEnd(StringExaminer iterator)
protected boolean matchReverse(java.lang.String pattern, StringExaminer probeIterator)
protected boolean charsAreEqual(char probeChar, char patternChar)
protected boolean endReached(char character)
protected boolean endNotReached(char character)
protected char getPatternChar(StringExaminer patternIterator, char probeCh)
protected StringExaminer newExaminer(java.lang.String str)
protected StringUtil strUtil()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |