heasarc.util
Class NumberParser

java.lang.Object
  |
  +--heasarc.util.NumberParser

public class NumberParser
extends java.lang.Object

This class provides routines for efficient parsing of character arrays.


Constructor Summary
NumberParser(char[] input)
          Construct a parser.
 
Method Summary
 int getNumberLength()
          Get the number of characters used to parse the previous number
 int getOffset()
          Get the current offset
static void main(java.lang.String[] args)
          Test routine
 boolean readBoolean(int length)
          Get a boolean value.
 double readDouble(int length)
          Convert a segment to a double.
 float readFloat(int length)
          Convert a segment to a float Leading spaces are ignored.
 int readInt(int length)
          Convert a segment to an int Leading spaces are ignored.
 long readLong(int length)
          Convert a segment to a long Leading spaces are ignored.
 java.lang.String readString(int length)
          Get a string (trimmed on the right)
 void setOffset(int offset)
          Set the offset into the array.
 int skipWhite(int length)
          Skip white space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberParser

public NumberParser(char[] input)
Construct a parser.
Parameters:
input - The character array to be parsed.
Method Detail

main

public static void main(java.lang.String[] args)
Test routine

setOffset

public void setOffset(int offset)
Set the offset into the array.
Parameters:
offset - The desired offset from the beginning of the array.

getOffset

public int getOffset()
Get the current offset

getNumberLength

public int getNumberLength()
Get the number of characters used to parse the previous number

readDouble

public double readDouble(int length)
Convert a segment to a double. Leading spaces are ignored.
Parameters:
length - The maximum number of characters used to parse this number

readFloat

public float readFloat(int length)
Convert a segment to a float Leading spaces are ignored.
Parameters:
length - The maximum number of characters used to parse this number

readInt

public int readInt(int length)
Convert a segment to an int Leading spaces are ignored.
Parameters:
length - The maximum number of characters used to parse this number

readLong

public long readLong(int length)
Convert a segment to a long Leading spaces are ignored.
Parameters:
length - The maximum number of characters used to parse this number

readString

public java.lang.String readString(int length)
Get a string (trimmed on the right)
Parameters:
length - The maximum length of the string.

readBoolean

public boolean readBoolean(int length)
Get a boolean value. Any string starting with a 't' or 'T' is assumed to be true. All other strings are false.
Parameters:
length - The segment search length.

skipWhite

public int skipWhite(int length)
Skip white space. This routine skips with space in the input and returns the number of character skipped. White space is defined as ' ' or '\t'.
Parameters:
length - The maximum number of characters to skip.