Interface InputBuffer
- All Known Implementing Classes:
DefaultInputBuffer, IndentDedentInputBuffer, MutableInputBuffer
public interface InputBuffer
Abstraction of a simple char[] buffer holding the input text to be parsed.
-
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) Returns the character at the given index.extract(int start, int end) Constructs a newStringfrom all character between the given indices.extract(IndexRange range) Constructs a newStringfrom all character covered by the given IndexRange.extractLine(int lineNumber) Constructs a newStringcontaining all characters with the given line number except for the trailing newline.intReturns the number of lines in the input buffer.intgetOriginalIndex(int index) Translates the given index from the scope of this InputBuffer to the scope of the original, underlying char array.getPosition(int index) Returns the line and column number of the character with the given index encapsulated in aPositionobject.booleantest(int index, char[] characters) Determines whether the characters starting at the given index match the ones from the given array (in order).
-
Method Details
-
charAt
char charAt(int index) Returns the character at the given index. If the index is invalid the method returnsChars.EOI.- Parameters:
index- the index- Returns:
- the character at the given index or Chars.EOI.
-
test
boolean test(int index, char[] characters) Determines whether the characters starting at the given index match the ones from the given array (in order).- Parameters:
index- the index into the input buffer where to start the comparisoncharacters- the characters to test against the input buffer- Returns:
- true if matched
-
extract
-
extract
Constructs a newStringfrom all character covered by the given IndexRange.- Parameters:
range- the IndexRange- Returns:
- a new String (non-interned)
-
getPosition
Returns the line and column number of the character with the given index encapsulated in aPositionobject. The very first character has the line number 1 and the column number 1.- Parameters:
index- the index of the character to get the line number of- Returns:
- the line number
-
getOriginalIndex
int getOriginalIndex(int index) Translates the given index from the scope of this InputBuffer to the scope of the original, underlying char array. TheDefaultInputBufferimplementation simply returns the given index, but other implementations like theIndentDedentInputBufferor theMutableInputBufferneed to "undo" all compressions and index shiftings performed internally in order to return the underlying index.- Parameters:
index- the index relative to this InputBuffer- Returns:
- the index relative to the underlying string or char array
-
extractLine
-
getLineCount
int getLineCount()Returns the number of lines in the input buffer.- Returns:
- number of lines in the input buffer.
-