Grammatica
Public Member Functions | Public Attributes | Properties | List of all members
PerCederberg.Grammatica.Runtime.ReaderBuffer Class Reference

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...
 

Detailed Description

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.

Author
Per Cederberg
Version
1.5
Since
1.5

Constructor & Destructor Documentation

PerCederberg.Grammatica.Runtime.ReaderBuffer.ReaderBuffer ( TextReader  input)
inline

Creates a new tokenizer character buffer.

Parameters
inputthe input source character reader

Member Function Documentation

void PerCederberg.Grammatica.Runtime.ReaderBuffer.Dispose ( )
inline

Discards all resources used by this buffer.

This will also close the source input stream. Disposing a previously disposed buffer has no effect.

int PerCederberg.Grammatica.Runtime.ReaderBuffer.Peek ( int  offset)
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.

Parameters
offsetthe character offset, from 0 and up
Returns
the character found as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream was reached
Exceptions
IOExceptionif an I/O error occurred
string PerCederberg.Grammatica.Runtime.ReaderBuffer.Read ( int  offset)
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.

Parameters
offsetthe character offset, from 0 and up
Returns
the string containing the characters read, or null no more characters remain in the buffer
Exceptions
IOExceptionif an I/O error occurred
string PerCederberg.Grammatica.Runtime.ReaderBuffer.Substring ( int  index,
int  length 
)
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.

Parameters
indexthe start index, inclusive
lengththe substring length
Returns
the substring specified
Exceptions
IndexOutOfBoundsExceptionif one of the indices were negative or not less than (or equal) than length()
override string PerCederberg.Grammatica.Runtime.ReaderBuffer.ToString ( )
inline

Returns the current content of the buffer as a string.

Note that content before the current position will also be returned.

Returns
the current buffer content

Member Data Documentation

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.

Property Documentation

int PerCederberg.Grammatica.Runtime.ReaderBuffer.ColumnNumber
get

The current column number property (read-only).

This number is the column number of the next character to read.

int PerCederberg.Grammatica.Runtime.ReaderBuffer.Length
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.

int PerCederberg.Grammatica.Runtime.ReaderBuffer.LineNumber
get

The current line number property (read-only).

This number is the line number of the next character to read.


The documentation for this class was generated from the following file: