org.parboiled.buffers
Class DefaultInputBuffer

java.lang.Object
  extended by org.parboiled.buffers.DefaultInputBuffer
All Implemented Interfaces:
InputBuffer
Direct Known Subclasses:
IndentDedentInputBuffer

public class DefaultInputBuffer
extends java.lang.Object
implements InputBuffer

Immutable default implementation of an InputBuffer.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.parboiled.buffers.InputBuffer
InputBuffer.Position
 
Field Summary
protected  char[] buffer
           
protected  int length
           
protected  int[] newlines
           
 
Constructor Summary
DefaultInputBuffer(char[] buffer)
          Constructs a new DefaultInputBuffer wrapping the given char array.
 
Method Summary
protected  void buildNewlines()
           
 char charAt(int index)
          Returns the character at the given index.
 java.lang.String extract(int start, int end)
          Constructs a new String from all character between the given indices.
 java.lang.String extractLine(int lineNumber)
          Constructs a new String containing all characters with the given line number except for the trailing newline.
protected static int getLine0(int[] newlines, int index)
           
 int getLineCount()
          Returns the number of lines in the input buffer.
 InputBuffer.Position getPosition(int index)
          Returns the line and column number of the character with the given index encapsulated in a InputBuffer.Position object.
 boolean test(int index, char[] characters)
          Determines whether the characters starting at the given index match the ones from the given array (in order).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

length

protected final int length

buffer

protected final char[] buffer

newlines

protected int[] newlines
Constructor Detail

DefaultInputBuffer

public DefaultInputBuffer(char[] buffer)
Constructs a new DefaultInputBuffer wrapping the given char array. CAUTION: For performance reasons the given char array is not defensively copied.

Parameters:
buffer - the chars
Method Detail

charAt

public char charAt(int index)
Description copied from interface: InputBuffer
Returns the character at the given index. If the index is invalid the method returns Chars.EOI.

Specified by:
charAt in interface InputBuffer
Parameters:
index - the index
Returns:
the character at the given index or Chars.EOI.

test

public boolean test(int index,
                    char[] characters)
Description copied from interface: InputBuffer
Determines whether the characters starting at the given index match the ones from the given array (in order).

Specified by:
test in interface InputBuffer
Parameters:
index - the index into the input buffer where to start the comparison
characters - the characters to test against the input buffer
Returns:
true if matched

extract

public java.lang.String extract(int start,
                                int end)
Description copied from interface: InputBuffer
Constructs a new String from all character between the given indices. Invalid indices are automatically adjusted to their respective boundary.

Specified by:
extract in interface InputBuffer
Parameters:
start - the start index (inclusively)
end - the end index (exclusively)
Returns:
a new String (non-interned)

getPosition

public InputBuffer.Position getPosition(int index)
Description copied from interface: InputBuffer
Returns the line and column number of the character with the given index encapsulated in a InputBuffer.Position object. The very first character has the line number 1 and the column number 1.

Specified by:
getPosition in interface InputBuffer
Parameters:
index - the index of the character to get the line number of
Returns:
the line number

getLine0

protected static int getLine0(int[] newlines,
                              int index)

extractLine

public java.lang.String extractLine(int lineNumber)
Description copied from interface: InputBuffer
Constructs a new String containing all characters with the given line number except for the trailing newline.

Specified by:
extractLine in interface InputBuffer
Parameters:
lineNumber - the line number to get
Returns:
the string

getLineCount

public int getLineCount()
Description copied from interface: InputBuffer
Returns the number of lines in the input buffer.

Specified by:
getLineCount in interface InputBuffer
Returns:
number of lines in the input buffer.

buildNewlines

protected void buildNewlines()