net.charlesames.utility.io
Class ParsingBuffer

java.lang.Object
  extended by net.charlesames.utility.io.ParsingBuffer

public class ParsingBuffer
extends java.lang.Object

Parsing buffer.

Author:
Charles Ames

Constructor Summary
ParsingBuffer()
          Constructor for ParsingBuffer instances.
 
Method Summary
 char charAt(int index)
          Get the character value at the indicated index.
 void checkIfEmpty()
          Check if there are more characters to parse.
 char currentChar()
          Get the character value at the text pointer.
 boolean empty()
           
 char getChar()
           
 int getIndex()
           
 java.lang.String getRemainingText()
           
 java.lang.String getText()
           
 java.lang.String getText(int length)
           
 int getTextLength()
           
 boolean matches(java.lang.String value)
          Test if the upcoming text matches the indicated value.
 int nextIndex()
           
 double parseDouble()
           
 int parseInt()
           
 long parseLong()
           
 Ratio parseRatio()
          Parse a ratio in long-colon-long format.
 java.lang.String parseSymbol()
           
 java.lang.String parseText()
           
 void parseWhitespace()
          Skips over whitespace in the parsing buffer.
 void setIndex(int index)
          Set the text pointer.
 void setText(java.lang.String text)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParsingBuffer

public ParsingBuffer()
Constructor for ParsingBuffer instances.

Method Detail

setText

public void setText(java.lang.String text)
Parameters:
text - The text to parse.

empty

public boolean empty()
Returns:
True if the text pointer falls short of the text length; false otherwise.

currentChar

public char currentChar()
Get the character value at the text pointer.

Returns:
The character value at the text pointer.

charAt

public char charAt(int index)
Get the character value at the indicated index.

Parameters:
index - The indicated index.
Returns:
The character value at the indicated index; null if index overflows text length.

getIndex

public int getIndex()
Returns:
The text pointer.

setIndex

public void setIndex(int index)
Set the text pointer.

Parameters:
index - The intended text pointer

getTextLength

public int getTextLength()
Returns:
The text length.

getRemainingText

public java.lang.String getRemainingText()
Returns:
The text remaining to be parsed.

getText

public java.lang.String getText()
Returns:
The full text.

getText

public java.lang.String getText(int length)
Parameters:
length - The number of characters wanted
Returns:
The next length characters remaining to be parsed.

matches

public boolean matches(java.lang.String value)
Test if the upcoming text matches the indicated value. If so, consume the text and return true. If not, do not consume any text and return false.

Parameters:
value - The text to match.
Returns:
True if the upcoming text matches the indicated value; false otherwise.

getChar

public char getChar()
             throws ParsingException
Returns:
The character value at the text pointer, which increments once the value has been extracted.
Throws:
ParsingException

nextIndex

public int nextIndex()
Returns:
Increments the text pointer. If the result falls short of the text length, then -1 is returned. Otherwise the text pointer is returned.

checkIfEmpty

public void checkIfEmpty()
                  throws ParsingException
Check if there are more characters to parse.

Throws:
ParsingException - when there are no more characters to parse.

parseWhitespace

public void parseWhitespace()
Skips over whitespace in the parsing buffer.


parseInt

public int parseInt()
             throws java.lang.NumberFormatException
Returns:
An integer parsed from the text.
Throws:
java.lang.NumberFormatException

parseLong

public long parseLong()
               throws java.lang.NumberFormatException
Returns:
A long parsed from the text.
Throws:
java.lang.NumberFormatException

parseRatio

public Ratio parseRatio()
                 throws java.lang.NumberFormatException
Parse a ratio in long-colon-long format.

Returns:
A ratio parsed from the text.
Throws:
java.lang.NumberFormatException

parseDouble

public double parseDouble()
                   throws java.lang.Exception
Returns:
A decimal number parsed from the text.
Throws:
java.lang.Exception

parseSymbol

public java.lang.String parseSymbol()
                             throws ParsingException
Returns:
A string of letters and numbers, starting with a letter, parsed from the text.
Throws:
ParsingException

parseText

public java.lang.String parseText()
                           throws java.lang.Exception
Returns:
A string of characters, not including whitespace, parsed from the text.
Throws:
java.lang.Exception