FileDocCategorySizeDatePackage
StringExaminer.javaAPI DocAzureus 3.0.3.46874Fri Mar 12 11:00:20 GMT 2004org.pf.text

StringExaminer

public class StringExaminer extends StringScanner
As a subclass of StringScanner this class allows more advanced navigation over the underlying string.
That includes moving to positions of specific substrings etc.
author
Manfred Duchrow
version
1.0

Fields Summary
private boolean
ignoreCase
Constructors Summary
public StringExaminer(String stringToExamine)
Initialize the new instance with the string to examine.
The string will be treated case-sensitive.

param
stringToExamine The string that should be examined

    this( stringToExamine, false ) ;
  
public StringExaminer(String stringToExamine, boolean ignoreCase)
Initialize the new instance with the string to examine.

param
stringToExamine The string that should be examined
param
ignoreCase Specified whether or not treating the string case insensitive

    super( stringToExamine ) ;
    this.ignoreCase( ignoreCase ) ;
  
Methods Summary
protected booleancharsAreEqual(char char1, char char2)

		return ( this.ignoreCase() ) 
							? ( Character.toUpperCase(char1) == Character.toUpperCase( char2 ) )
							: ( char1 == char2 ) ;
	
protected booleanignoreCase()

      return ignoreCase ; 
protected voidignoreCase(boolean newValue)

 ignoreCase = newValue ; 
public java.lang.StringpeekUpToEnd()
Returns the a string containing all characters from the current position up to the end of the examined string.
The character position of the examiner is not changed by this method.

		return this.upToEnd( true ) ;
	
public booleanskipAfter(java.lang.String matchString)
Increments the position pointer up to the last character that matched the character sequence in the given matchString. Returns true, if the matchString was found, otherwise false.

If the matchString was found, the next invocation of method nextChar() returns the first character after that matchString.

param
matchString The string to look up

		char ch			= '-" ;
		char matchChar = ' " ;
		boolean found = false ;
		int index = 0 ;
		
		if ( ( matchString == null ) || ( matchString.length() == 0 ) )
			return false ;
		
		ch = this.nextChar() ;
		while ( ( endNotReached( ch ) ) && ( ! found ) )  
		{
			matchChar = matchString.charAt( index ) ;
			if ( this.charsAreEqual( ch, matchChar ) )
			{
				index++ ;
				if ( index >= matchString.length() ) // whole matchString checked ?
				{
					found = true ;
				}
				else
				{
					ch = this.nextChar() ;
				}
			}
			else
			{
				if ( index == 0 )
				{
					ch = this.nextChar() ;
				}
				else
				{
					index = 0 ;	
				}
			}
		}
		return found ;
	
public booleanskipBefore(java.lang.String matchString)
Increments the position pointer up to the first character before the character sequence in the given matchString. Returns true, if the matchString was found, otherwise false.

If the matchString was found, the next invocation of method nextChar() returns the first character of that matchString from the position where it was found inside the examined string.

param
matchString The string to look up

		boolean found ;
		
		found = this.skipAfter( matchString ) ;
		if ( found )
			this.skip( 0 - matchString.length() ) ;
			
		return found ;
	
protected java.lang.StringupToEnd(boolean peek)
Returns the a string containing all characters from the current position up to the end of the examined string.
Depending on the peek flag the character position of the examiner is unchanged (true) after calling this method or points behind the strings last character.

		char result			= '-" ;
		int lastPosition = 0 ;
		StringBuffer buffer = new StringBuffer( 100 ) ;
		
		lastPosition = this.getPosition() ;
		result = this.nextChar() ;
		while ( endNotReached( result ) ) 
		{
			buffer.append( result ) ;
			result = this.nextChar() ;
		}
		if ( peek )
			this.setPosition( lastPosition ) ;
			
		return buffer.toString() ;
	
public java.lang.StringupToEnd()
Returns the a string containing all characters from the current position up to the end of the examined string.
The character position is put to the end by this method. That means the next invocation of nextChar() returns END_REACHED.

		return this.upToEnd( false ) ;