org.inria.ns.reflex.util
Class StringScanner

java.lang.Object
  extended by org.inria.ns.reflex.util.Scanner
      extended by org.inria.ns.reflex.util.StringScanner

public class StringScanner
extends Scanner

A scanner for sequences of chars (i.e. strings).

Author:
Philippe Poulard
See Also:
ReaderScanner

Constructor Summary
StringScanner(CharSequence sequence)
          Create a new scanner.
 
Method Summary
 void cancel()
          Cancel the characters read since the last marked position (the next read will start from the last marked position).
 void consume()
          Consume the characters read so far.
 Reader getRemainder()
          Return the remainder to read from the current position.
 String getRemainderString()
          Return the remainder to read from the current position.
 void mark(int limit)
          Mark the present position in the stream.
 void read()
          Read the next character.
 
Methods inherited from class org.inria.ns.reflex.util.Scanner
getPosition, getSourceIndex, hasNext, hasNextChar, hasNextChar, hasNextString, lookAhead, nextChar, nextChar, nextNumber, nextNumber, nextObject, nextString, nextString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringScanner

public StringScanner(CharSequence sequence)
Create a new scanner.

Parameters:
reader - The input to read.
Method Detail

read

public void read()
Read the next character.

Specified by:
read in class Scanner
See Also:
#hasNextChar(char), Scanner.nextChar(), Scanner.lookAhead()

mark

public void mark(int limit)
Mark the present position in the stream.

This method can be called safely several times.

For each mark set, there should be sooner or later a consume or cancel.

Some convenient methods are available for getting a single character without using a mark : Scanner.lookAhead(), Scanner.nextChar(), Scanner.hasNextChar(char, boolean) and Scanner.hasNextChar(String, boolean).

Specified by:
mark in class Scanner
Parameters:
limit - The maximum number of characters that can be read before loosing the mark.
See Also:
Reader.mark(int), cancel(), consume()

cancel

public void cancel()
Cancel the characters read since the last marked position (the next read will start from the last marked position).

Specified by:
cancel in class Scanner
Throws:
IllegalStateException - When this method is called whereas no position was marked so far.
See Also:
mark(int)

consume

public void consume()
             throws IOException
Consume the characters read so far.

This implies that the last marked position is removed and the next read goes on from the current position. If there wasn't other marker, it will be impossible to go back. If there was at least another one marker, it can be itself cancelled or consumed independently.

Specified by:
consume in class Scanner
Throws:
IOException - When an I/O error occur.
IllegalStateException - When this method is called whereas no position was marked so far.
See Also:
mark(int)

getRemainder

public Reader getRemainder()
Return the remainder to read from the current position.

Specified by:
getRemainder in class Scanner
Returns:
The remainder to read, or null if the end was reached.
See Also:
Scanner.getRemainderString()

getRemainderString

public String getRemainderString()
Return the remainder to read from the current position.

Specified by:
getRemainderString in class Scanner
Returns:
The remainder to read, or null if the end was reached.
See Also:
Scanner.getRemainder()