pobs.scanner
Class PTextScanner

java.lang.Object
  extended bypobs.scanner.PTextScanner
All Implemented Interfaces:
PScanner

public class PTextScanner
extends java.lang.Object
implements PScanner

A PTextScannerdecorator which returns line and column numbers of a texts with newline and tab characters.

Author:
Franz-Josef Elmer

Constructor Summary
PTextScanner(PScanner scanner)
          Creates an instance for the specified scanner.
PTextScanner(PScanner scanner, int tabStep)
          Creates an instance for the specified scanner and tabulator step.
 
Method Summary
 char charAt(long index)
          Returns the character at the specified location.
 PPosition getPosition(long index)
          Returns the number of lines and columns between from the start of the input upto the specified index.
 PPosition getRelativePosition(long from, long to)
          Returns the number of lines and columns between the from and to indexes.
 long length()
          Gives the length of this scanners' content.
 java.lang.String substring(long beginIndex, long endIndex)
          Returns the part of the input from the beginning upto the ending index locations.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PTextScanner

public PTextScanner(PScanner scanner)
Creates an instance for the specified scanner. Short cut of new PTextScanner(scanner, 8).

Parameters:
scanner - Wrapped scanner instance. null is not allowed.

PTextScanner

public PTextScanner(PScanner scanner,
                    int tabStep)
Creates an instance for the specified scanner and tabulator step.

Parameters:
scanner - Wrapped scanner instance. null is not allowed.
tabStep - Tabulator step used to calculate the column number when an ASCII TAB character occurs. Must be a positive number.
Throws:
java.lang.IllegalArgumentException - if one of the two conditions at the arguments are violated.
Method Detail

charAt

public char charAt(long index)
            throws java.lang.IndexOutOfBoundsException
Description copied from interface: PScanner
Returns the character at the specified location.

Specified by:
charAt in interface PScanner
Parameters:
index - position of the character to return
Returns:
character at the specified index
Throws:
java.lang.IndexOutOfBoundsException - when the specified index is either less than zero or equal or more than the length

length

public long length()
Description copied from interface: PScanner
Gives the length of this scanners' content. That is; the last position which can be indexed.

Specified by:
length in interface PScanner
Returns:
the length of this iterator.

substring

public java.lang.String substring(long beginIndex,
                                  long endIndex)
Description copied from interface: PScanner
Returns the part of the input from the beginning upto the ending index locations.

Specified by:
substring in interface PScanner
Parameters:
beginIndex - starting offset from which to extract the substring
endIndex - ending offset at which the substring ends
Returns:
the substring
See Also:
String

getPosition

public PPosition getPosition(long index)
Returns the number of lines and columns between from the start of the input upto the specified index.

Parameters:
index - the index upto which is counted

getRelativePosition

public PPosition getRelativePosition(long from,
                                     long to)
Returns the number of lines and columns between the from and to indexes.

Parameters:
from - the base index from where to start counting
to - the index upto which is counted