Grammatica
|
A character buffer that automatically reads from an input source stream when needed. More...
Public Member Functions | |
ReaderBuffer (TextReader input) | |
Creates a new tokenizer character buffer. More... | |
void | Dispose () |
Discards all resources used by this buffer. More... | |
string | Substring (int index, int length) |
Returns a substring already in the buffer. More... | |
override string | ToString () |
Returns the current content of the buffer as a string. More... | |
int | Peek (int offset) |
Returns a character relative to the current position. More... | |
string | Read (int offset) |
Reads the specified number of characters from the current position. More... | |
Public Attributes | |
const int | BLOCK_SIZE = 1024 |
The stream reading block size. More... | |
Properties | |
int | Position [get] |
The current buffer position property (read-only). | |
int | LineNumber [get] |
The current line number property (read-only). More... | |
int | ColumnNumber [get] |
The current column number property (read-only). More... | |
int | Length [get] |
The current character buffer length property (read-only). More... | |
A character buffer that automatically reads from an input source stream when needed.
This class keeps track of the current position in the buffer and its line and column number in the original input source. It allows unlimited look-ahead of characters in the input, reading and buffering the required data internally. As the position is advanced, the buffer content prior to the current position is subject to removal to make space for reading new content. A few characters before the current position are always kept to enable boundary condition checks.
|
inline |
Creates a new tokenizer character buffer.
input | the input source character reader |
|
inline |
Discards all resources used by this buffer.
This will also close the source input stream. Disposing a previously disposed buffer has no effect.
|
inline |
Returns a character relative to the current position.
This method may read from the input source and may also trim the buffer content prior to the current position. The result of calling this method may therefore be that the buffer length and content have been modified.
The character offset must be positive, but is allowed to span the entire size of the input source stream. Note that the internal buffer must hold all the intermediate characters, which may be wasteful if the offset is too large.
offset | the character offset, from 0 and up |
IOException | if an I/O error occurred |
|
inline |
Reads the specified number of characters from the current position.
This will also move the current position forward. This method will not attempt to move beyond the end of the input source stream. When reaching the end of file, the returned string might be shorter than requested. Any remaining characters will always be returned before returning null.
offset | the character offset, from 0 and up |
IOException | if an I/O error occurred |
|
inline |
Returns a substring already in the buffer.
Note that this method may behave in unexpected ways when performing operations that modifies the buffer content.
index | the start index, inclusive |
length | the substring length |
IndexOutOfBoundsException | if one of the indices were negative or not less than (or equal) than length() |
|
inline |
Returns the current content of the buffer as a string.
Note that content before the current position will also be returned.
const int PerCederberg.Grammatica.Runtime.ReaderBuffer.BLOCK_SIZE = 1024 |
The stream reading block size.
All reads from the underlying character stream will be made in multiples of this block size. Also the character buffer size will always be a multiple of this factor.
|
get |
The current column number property (read-only).
This number is the column number of the next character to read.
|
get |
The current character buffer length property (read-only).
Note that the length may increase (and decrease) as more characters are read from the input source or removed to free up space.
|
get |
The current line number property (read-only).
This number is the line number of the next character to read.