Constructors Summary |
---|
public StringPattern(String pattern)Initializes the new instance with the string pattern.
The default is case sensitive checking.
this( pattern, false) ;
|
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.
this( pattern, false, digitWildcard ) ;
|
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.
this.setPattern( pattern ) ;
this.setIgnoreCase( ignoreCase ) ;
this.setDigitWildcardChar( digitWildcard ) ;
|
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.
this.setPattern( pattern ) ;
this.setIgnoreCase( ignoreCase ) ;
|
Methods Summary |
---|
protected boolean | charsAreEqual(char probeChar, char patternChar)
if ( this.hasDigitWildcard() )
{
if ( patternChar == this.digitWildcardChar() )
{
return Character.isDigit( probeChar ) ;
}
}
if ( this.getIgnoreCase() )
{
return ( Character.toUpperCase(probeChar) == Character.toUpperCase( patternChar ) ) ;
}
else
{
return ( probeChar == patternChar ) ;
}
|
protected java.lang.Character | digitWildcard()
return digitWildcard ;
|
protected void | digitWildcard(java.lang.Character newValue) digitWildcard = newValue ;
|
protected char | digitWildcardChar()
if ( this.hasDigitWildcard() )
return this.digitWildcard().charValue() ;
else
return '\0" ;
|
protected boolean | endNotReached(char character)
return ( ! endReached( character ) ) ;
|
protected boolean | endReached(char character)
return ( character == StringExaminer.END_REACHED ) ;
|
public boolean | getIgnoreCase()Returns whether or not the pattern matching ignores upper and lower case
return ignoreCase ;
|
public java.lang.String | getPattern()Returns the pattern as string.
return pattern ;
|
protected char | getPatternChar(StringExaminer patternIterator, char probeCh)
char patternCh ;
patternCh = patternIterator.nextChar() ;
return ( ( patternCh == SINGLECHAR_WILDCARD ) ? probeCh : patternCh ) ;
|
protected boolean | hasDigitWildcard()
return this.digitWildcard() != null ;
|
public boolean | hasWildcard()Returns true if the pattern contains any '*' or '?' wildcard character.
if ( this.getPattern() == null )
return false ;
if ( this.hasDigitWildcard() )
{
if ( this.getPattern().indexOf( this.digitWildcardChar() ) >= 0 )
return true ;
}
return ( this.getPattern().indexOf( MULTI_WILDCARD ) >= 0 ) ||
( this.getPattern().indexOf( SINGLECHAR_WILDCARD ) >= 0 ) ;
|
public static boolean | match(java.lang.String probe, java.lang.String pattern)Returns true, if the given probe string matches the given pattern.
The character comparison is done case sensitive.
StringPattern stringPattern = new StringPattern( pattern, false ) ;
return ( stringPattern.matches( probe ) ) ;
|
public static boolean | matchIgnoreCase(java.lang.String probe, java.lang.String pattern)Returns true, if the given probe string matches the given pattern.
The character comparison is done ignoring upper/lower-case.
StringPattern stringPattern = new StringPattern( pattern, true ) ;
return ( stringPattern.matches( probe ) ) ;
|
protected boolean | matchReverse(java.lang.String pattern, StringExaminer probeIterator)
String newPattern ;
String newProbe ;
StringPattern newMatcher ;
newPattern = MULTI_WILDCARD + pattern ;
newProbe = this.upToEnd( probeIterator ) ;
newPattern = this.strUtil().reverse( newPattern ) ;
newProbe = this.strUtil().reverse( newProbe ) ;
newMatcher = new StringPattern( newPattern, this.getIgnoreCase() ) ;
if ( this.hasDigitWildcard() )
newMatcher.setDigitWildcardChar( this.digitWildcardChar() ) ;
return newMatcher.matches( newProbe ) ;
|
public boolean | matches(java.lang.String probe)Tests if a specified string matches the pattern.
StringExaminer patternIterator = null ;
StringExaminer probeIterator = null ;
char patternCh = '-" ;
char probeCh = '-" ;
String newPattern = null ;
String subPattern = null ;
int charIndex = 0 ;
if ( probe == null ) return false ;
if ( probe.length() == 0 ) return false ;
patternIterator = this.newExaminer( this.getPattern() ) ;
probeIterator = this.newExaminer( probe ) ;
probeCh = probeIterator.nextChar() ;
patternCh = this.getPatternChar( patternIterator, probeCh ) ;
while ( ( this.endNotReached( patternCh ) ) &&
( this.endNotReached( probeCh ) ) )
{
if ( patternCh == MULTICHAR_WILDCARD )
{
patternCh = this.skipWildcards( patternIterator ) ;
if ( this.endReached( patternCh ) )
{
return true ; // No more characters after multi wildcard - So everything matches
}
else
{
patternIterator.skip(-1) ;
newPattern = this.upToEnd( patternIterator ) ;
charIndex = newPattern.indexOf( MULTICHAR_WILDCARD ) ;
if ( charIndex >= 0 )
{
subPattern = newPattern.substring( 0, charIndex ) ;
if ( this.skipAfter( probeIterator, subPattern ) )
{
patternIterator = this.newExaminer( newPattern.substring( charIndex ) ) ;
patternCh = probeCh ;
}
else
{
return false ;
}
}
else
{
probeIterator.skip(-1) ;
return this.matchReverse( newPattern, probeIterator ) ;
}
}
}
if ( this.charsAreEqual( probeCh, patternCh ) )
{
if ( this.endNotReached(patternCh) )
{
probeCh = probeIterator.nextChar() ;
patternCh = this.getPatternChar( patternIterator, probeCh ) ;
}
}
else
{
if ( patternCh != MULTICHAR_WILDCARD )
return false ; // character is not matching - return immediately
}
} // while()
return ( ( this.endReached( patternCh ) ) && ( this.endReached( probeCh ) ) ) ;
|
protected StringExaminer | newExaminer(java.lang.String str)
return new StringExaminer( str, this.getIgnoreCase() ) ;
|
public void | setDigitWildcardChar(char digitWildcard)Sets the given character as a wildcard character in this pattern to
match only digits ('0'-'9').
if ( digitWildcard <= 0 )
{
this.digitWildcard( null ) ;
}
else
{
this.digitWildcard( new Character( digitWildcard ) ) ;
}
|
public void | setIgnoreCase(boolean newValue)Sets whether the pattern matching should ignore case or not ignoreCase = newValue ;
|
public void | setPattern(java.lang.String newValue)Sets the pattern to a new value pattern = newValue ;
|
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.
Returns true, if the matchString was found, otherwise false.
// Do not use the method of StringExaminer anymore, because digit wildcard
// support is in the charsAreEqual() method which is unknown to the examiner.
// return examiner.skipAfter( matchString ) ;
char ch = '-" ;
char matchChar = ' " ;
boolean found = false ;
int index = 0 ;
if ( ( matchString == null ) || ( matchString.length() == 0 ) )
return false ;
ch = examiner.nextChar() ;
while ( ( examiner.endNotReached( ch ) ) && ( ! found ) )
{
matchChar = matchString.charAt( index ) ;
if ( this.charsAreEqual( ch, matchChar ) )
{
index++ ;
if ( index >= matchString.length() ) // whole matchString checked ?
{
found = true ;
}
else
{
ch = examiner.nextChar() ;
}
}
else
{
if ( index == 0 )
{
ch = examiner.nextChar() ;
}
else
{
index = 0 ;
}
}
}
return found ;
|
protected char | skipWildcards(StringExaminer iterator)Moves the iterator position to the next character that is no wildcard.
Doesn't skip digit wildcards !
char result = '-" ;
do
{
result = iterator.nextChar() ;
}
while ( ( result == MULTICHAR_WILDCARD ) || ( result == SINGLECHAR_WILDCARD ) ) ;
return result ;
|
protected StringUtil | strUtil()
return StringUtil.current() ;
|
public java.lang.String | toString()Returns the pattern string.
if ( this.getPattern() == null )
return super.toString() ;
else
return this.getPattern() ;
|
protected java.lang.String | upToEnd(StringExaminer iterator)
return iterator.upToEnd() ;
|