com.meyling.principia.io
Class TextInput

java.lang.Object
  |
  +--com.meyling.principia.io.TextInput

public class TextInput
extends Object

This class provides convenient methods for parsing input. TODO offer input stream constructor

Version:
$Revision 0.00.50$
Author:
Michael Meyling

Field Summary
private  String address
          address of input, for identifing address
private  int column
          current column (starting with 0)
private static char CR
          char marking end of input line
private static char EOF
          char marking end of data
private  int lineNumber
          current line number (starting with 0)
private  String localAddress
          local address of input, for identifing address
private static String MARKER
          string for marking current reading position
private  int position
          current reading position
private  StringBuffer source
          holds the data
 
Constructor Summary
TextInput(StringBuffer source, String address, String localAddress)
          Constructor using StringBuffer source.
TextInput(String source, String address, String localAddress)
          Constructor using String source.
 
Method Summary
 String getAddress()
          Get address (or something to identify it) of input source.
 char getChar()
          Reads a single character and does not change the reading position.
 char getChar(int i)
          Reads a single character and does not change the reading position.
 int getColumn()
          Returns the current column number.
 String getLine()
          Returns the current line.
 String getLocalAddress()
          Get local address (or something to identify it) of input source.
 int getMaximumPosition()
          Returns the highest position number possible.
 int getPosition()
          Returns the current position.
 int getRow()
          Returns the current line number.
 boolean isEmpty()
          Is there no data left for reading?
 char readChar()
          Reads a single character and increments the reading position by one.
 int readCounter()
          Reads the next positive integer made completly out of digits, leading whitespace is skipped.
 String readLetterDigitString()
          Reads the next string containing only letters or digits, leading whitespace is skipped.
 String readQuoted()
          Reads the next quoted string, leading whitespace is skipped.
 void setPosition(int position)
          Sets the current position (and indirectly the line number).
 String showLinePosition()
          Show reading position.
 void skipWhiteSpace()
          Skips white space, beginning from reading position.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

EOF

private static final char EOF
char marking end of data

CR

private static final char CR
char marking end of input line

MARKER

private static final String MARKER
string for marking current reading position

source

private final StringBuffer source
holds the data

lineNumber

private int lineNumber
current line number (starting with 0)

column

private int column
current column (starting with 0)

position

private int position
current reading position

address

private final String address
address of input, for identifing address

localAddress

private final String localAddress
local address of input, for identifing address
Constructor Detail

TextInput

public TextInput(StringBuffer source,
                 String address,
                 String localAddress)
Constructor using StringBuffer source.
Parameters:
source - data source
address - for identifing source
localAddress - source address
Throws:
IllegalArgumentException - if argument was an nullpointer

TextInput

public TextInput(String source,
                 String address,
                 String localAddress)
Constructor using String source.
Parameters:
source - data source
address - for identifing source
localAddress - source address
Throws:
IllegalArgumentException - if argument was an nullpointer
Method Detail

readChar

public final char readChar()
Reads a single character and increments the reading position by one.
Returns:
character read, if there are no more chars Character.MAX_VALUE is returned

getChar

public final char getChar()
Reads a single character and does not change the reading position.
Returns:
character read, if there are no more chars Character.MAX_VALUE is returned

getChar

public final char getChar(int i)
Reads a single character and does not change the reading position.
Parameters:
i - offset from current reading position.
Returns:
character read, if there are no more chars Character.MAX_VALUE is returned

skipWhiteSpace

public final void skipWhiteSpace()
Skips white space, beginning from reading position. Changes reading position to next non white space character.

isEmpty

public final boolean isEmpty()
Is there no data left for reading?
Returns:
is all data read?

readLetterDigitString

public final String readLetterDigitString()
Reads the next string containing only letters or digits, leading whitespace is skipped. Changes reading position.
Returns:
read string
Throws:
IllegalArgumentException - if no such characters could be found

readCounter

public final int readCounter()
Reads the next positive integer made completly out of digits, leading whitespace is skipped. Changes reading position.
Returns:
read integer
Throws:
IllegalArgumentException - if no digits where found or the number was to big for an int

readQuoted

public final String readQuoted()
                        throws IllegalArgumentException
Reads the next quoted string, leading whitespace is skipped. A correctly quoted string could be created by adding a leading and a trailing quote character and doubling each other quote character. The resulting string is dequoted. Changes reading position.
Returns:
deqoted read string
Throws:
IllegalArgumentException - if no correctly quoted string was found

getRow

public final int getRow()
Returns the current line number.
Returns:
current line number (starting with line 1)

getColumn

public final int getColumn()
Returns the current column number.
Returns:
current column number (starting with line 1)

getLine

public final String getLine()
Returns the current line.
Returns:
current line

getPosition

public final int getPosition()
Returns the current position.
Returns:
current position

getMaximumPosition

public final int getMaximumPosition()
Returns the highest position number possible. This is equal to the length of the source.
Returns:
maximum position

setPosition

public final void setPosition(int position)
Sets the current position (and indirectly the line number).
Parameters:
position - set current position

getAddress

public final String getAddress()
Get address (or something to identify it) of input source.
Returns:
address of input source

getLocalAddress

public final String getLocalAddress()
Get local address (or something to identify it) of input source.
Returns:
local address of input source

showLinePosition

public final String showLinePosition()
Show reading position.
Returns:
current line with mark at current reading position