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

StringScanner

public class StringScanner extends Object
Simple scanner that allows to navigate over the characters of a string.
author
Manfred Duchrow
version
1.1

Fields Summary
public static final char
END_REACHED
protected int
length
protected int
position
protected int
pos_marker
protected char[]
buffer
Constructors Summary
public StringScanner(String stringToScan)
Initialize the new instance with the string that should be scanned.

    super() ;
    length = stringToScan.length() ;
    buffer = new char[length] ;
    stringToScan.getChars( 0, length, buffer, 0 ) ;
  
Methods Summary
public booleanatEnd()
Returns true, if the scanner has reached the end and a further invocation of nextChar() would return the END_REACHED character.

		return ( endReached( this.peek() ) ) ;
	
public booleanendNotReached(char character)
Returns true, if the given character does not indicate that the end of the scanned string si reached.

		return ( ! endReached( character ) ) ;
	
public booleanendReached(char character)
Returns true, if the given character indicates that the end of the scanned string is reached.


  // =========================================================================
  // PUBLIC CLASS METHODS
  // =========================================================================
                     
       
	
		return ( character == END_REACHED ) ;
	
public intgetPosition()
Returns the current position in the string

    return position ;
  
public booleanhasNext()
Returns true, if the scanner has not yet reached the end.

		return ! this.atEnd() ;
	
protected intlength()

    return length ;
  
public voidmarkPosition()
Remembers the current position for later use with restorePosition()

    pos_marker = position ;
  
public charnextChar()
Returns the character at the current position and increments the position afterwards by 1.

    char next = this.peek() ;
    if ( endNotReached( next ) )
	    this.skip(1);
    return next ;
  
public charnextNoneWhitespaceChar()
Returns the next character that is no whitespace and leaves the position pointer one character after the returned one.

    char next = this.nextChar() ;
    while ( ( endNotReached( next ) ) && ( Character.isWhitespace(next) ) )
    {
      next = this.nextChar() ;
    }
    return next ;
  
public charpeek()
Returns the character at the current position without changing the position, that is subsequent calls to this method return always the same character.

    return ( position < length() ? buffer[position] : END_REACHED ) ;
  
public voidrestorePosition()
Restores the position to the value of the latest markPosition() call

    this.setPosition( pos_marker  ) ;
  
protected voidsetPosition(int pos)

		if ( ( pos >= 0 ) && ( pos <= this.length() ) )
			position = pos ;
	
public voidskip(int count)
Moves the position pointer count characters. positive values move forwards, negative backwards. The position never becomes negative !

    position += count ;
    if ( position < 0 )
      position = 0 ;
  
public java.lang.StringtoString()
Returns the string the scanner was initialized with

    return new String( buffer ) ;