jfun.parsec
Class DefaultPositionMap

java.lang.Object
  extended by jfun.parsec.DefaultPositionMap
All Implemented Interfaces:
java.io.Serializable, PositionMap

public class DefaultPositionMap
extends java.lang.Object
implements PositionMap, java.io.Serializable

This default implementation of PositionMap.

This class internally keeps a cache of the positions of all the line break characters scanned so far, therefore repeated position lookup can be done in amortized log(n) time.

Author:
Ben Yu Dec 12, 2004
See Also:
Serialized Form

Constructor Summary
DefaultPositionMap(java.lang.CharSequence src, int lno, int cno)
          Create a DefaultPositionMap object.
DefaultPositionMap(java.lang.CharSequence src, int lno, int cno, char line_break)
          Create a DefaultPositionMap object.
 
Method Summary
 Pos getPos(int n)
          Get the line/column number of a position identified by an offset number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPositionMap

public DefaultPositionMap(java.lang.CharSequence src,
                          int lno,
                          int cno,
                          char line_break)
Create a DefaultPositionMap object.

Parameters:
src - the source.
lno - the starting line number.
cno - the starting column number.
line_break - the line break character.

DefaultPositionMap

public DefaultPositionMap(java.lang.CharSequence src,
                          int lno,
                          int cno)
Create a DefaultPositionMap object.

Parameters:
src - the source.
lno - the starting line number.
cno - the starting column number.
Method Detail

getPos

public Pos getPos(int n)
Description copied from interface: PositionMap
Get the line/column number of a position identified by an offset number.

Specified by:
getPos in interface PositionMap
Parameters:
n - the offset in the source, starting from 0.
Returns:
the Pos object.