Overview   Project   Class   Tree   Deprecated   Index 
Grammatica 1.5 Documentation
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD

PerCederberg.Grammatica.Runtime
Class ReaderBuffer

System.Object
   |
   +--ReaderBuffer

   in ReaderBuffer.cs

public class ReaderBuffer
extends System.Object

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.

Since:
1.5

Field Summary
 const int BLOCK_SIZE
          The stream reading block size.
 int ColumnNumber
          The current column number property (read-only).
 int Length
          The current character buffer length property (read-only).
 int LineNumber
          The current line number property (read-only).
 int Position
          The current buffer position property (read-only).
 
Constructor Summary
ReaderBuffer( TextReader input )
          Creates a new tokenizer character buffer.
 
Method Summary
 void Dispose()
          Discards all resources used by this buffer.
 int Peek( int offset )
          Returns a character relative to the current position.
 string Read( int offset )
          Reads the specified number of characters from the current position.
 string Substring( int index, int length )
          Returns a substring already in the buffer.
 override string ToString()
          Returns the current content of the buffer as a string.
 

Field Detail

BLOCK_SIZE

public const int BLOCK_SIZE;
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.

ColumnNumber

public int ColumnNumber;
The current column number property (read-only). This number is the column number of the next character to read.

Length

public int Length;
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.

LineNumber

public int LineNumber;
The current line number property (read-only). This number is the line number of the next character to read.

Position

public int Position;
The current buffer position property (read-only).


Constructor Detail

ReaderBuffer

public ReaderBuffer( TextReader input );
Creates a new tokenizer character buffer.
Parameters:
input - the input source character reader


Method Detail

Dispose

public void Dispose();
Discards all resources used by this buffer. This will also close the source input stream. Disposing a previously disposed buffer has no effect.

Peek

public int Peek( int offset );
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:
offset - the 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
Throws:
IOException - if an I/O error occurred

Read

public string Read( int offset );
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:
offset - the character offset, from 0 and up
Returns:
the string containing the characters read, or null no more characters remain in the buffer
Throws:
IOException - if an I/O error occurred

Substring

public string Substring( int index, int length );
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:
index - the start index, inclusive
length - the substring length
Returns:
the substring specified
Throws:
IndexOutOfBoundsException - if one of the indices were negative or not less than (or equal) than length()

ToString

public override string ToString();
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

 Overview   Project   Class   Tree   Deprecated   Index 
Grammatica 1.5 Documentation
FRAMES    NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD