public class MutableInputBuffer extends java.lang.Object implements InputBuffer
Modifier and Type | Field and Description |
---|---|
private InputBuffer |
buffer |
private char[] |
chars |
private int[] |
inserts |
Constructor and Description |
---|
MutableInputBuffer(InputBuffer buffer) |
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index)
Returns the character at the given index.
|
java.lang.String |
extract(IndexRange range)
Constructs a new
String from all character covered by the given IndexRange. |
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. |
int |
getLineCount()
Returns the number of lines in the input buffer.
|
int |
getOriginalIndex(int index)
Translates the given index from the scope of this InputBuffer to the scope of the original, underlying char
array.
|
Position |
getPosition(int index)
Returns the line and column number of the character with the given index encapsulated in a
Position
object. |
void |
insertChar(int index,
char c) |
private int |
map(int index) |
void |
replaceInsertedChar(int index,
char c) |
boolean |
test(int index,
char[] characters)
Determines whether the characters starting at the given index match the ones from the given array (in order).
|
char |
undoCharInsertion(int index) |
private final InputBuffer buffer
private int[] inserts
private char[] chars
public MutableInputBuffer(InputBuffer buffer)
public char charAt(int index)
InputBuffer
Chars.EOI
.charAt
in interface InputBuffer
index
- the indexpublic boolean test(int index, char[] characters)
InputBuffer
test
in interface InputBuffer
index
- the index into the input buffer where to start the comparisoncharacters
- the characters to test against the input bufferpublic Position getPosition(int index)
InputBuffer
Position
object. The very first character has the line number 1 and the column number 1.getPosition
in interface InputBuffer
index
- the index of the character to get the line number ofpublic int getOriginalIndex(int index)
InputBuffer
DefaultInputBuffer
implementation simply returns the given index, but other implementations
like the IndentDedentInputBuffer
or the MutableInputBuffer
need to "undo" all compressions and
index shiftings performed internally in order to return the underlying index.getOriginalIndex
in interface InputBuffer
index
- the index relative to this InputBufferpublic java.lang.String extractLine(int lineNumber)
InputBuffer
String
containing all characters with the given line number except for the trailing
newline.extractLine
in interface InputBuffer
lineNumber
- the line number to getpublic java.lang.String extract(int start, int end)
InputBuffer
String
from all character between the given indices.
Invalid indices are automatically adjusted to their respective boundary.extract
in interface InputBuffer
start
- the start index (inclusively)end
- the end index (exclusively)public java.lang.String extract(IndexRange range)
InputBuffer
String
from all character covered by the given IndexRange.extract
in interface InputBuffer
range
- the IndexRangepublic int getLineCount()
InputBuffer
getLineCount
in interface InputBuffer
private int map(int index)
public void insertChar(int index, char c)
public char undoCharInsertion(int index)
public void replaceInsertedChar(int index, char c)