jimmc.util
Class QuoteTokenizer

java.lang.Object
  |
  +--jimmc.util.QuoteTokenizer

public class QuoteTokenizer
extends java.lang.Object

Tokenize a String which may contain quoted strings.


Field Summary
static char INTRAQUOTER
          Our character-quoting character within a string.
protected  int len
          The length of the line being parsed.
protected  java.lang.String line
          The string we are parsing.
protected  int pos
          The position at which to start parsing on the next call to nextToken().
protected  java.lang.StringBuffer qbuf
          A buffer we use while parsing a quoted string.
protected  boolean quoted
          True if the string most recently returned by nextToken() was a quoted string.
static char QUOTER
          Our string quoting character.
 
Constructor Summary
QuoteTokenizer()
          Create a tokenizer.
QuoteTokenizer(java.lang.String line)
          Create a tokenizer for a string.
 
Method Summary
protected  java.lang.String getIdentifier()
          Parse out an identifier string.
protected  java.lang.Number getNumber()
          Get a number string.
protected  java.lang.String getQuoted()
          Parse out a quoted string.
protected  boolean isIdentiferPart(char c)
          True if this character can be in an identifier.
protected  boolean isIdentifierStart(char c)
          True if this character starts an identifier.
protected  boolean isNumberPart(char c)
          True if this character can be part of a number.
protected  boolean isNumberStart(char c)
          True if this character starts a number.
protected  boolean isQuotedStart(char c)
          True if this character starts a quoted string.
 java.lang.Object nextToken()
          Return the next token.
 void setInput(java.lang.String line)
          Set the string to be parsed.
protected  void skipWhitespace()
          Skip white space.
protected  java.lang.Number stringToNumber(java.lang.String s)
          Convert a string representation of a number to a Number.
 boolean wasQuoted()
          True if the string most recently returned by nextToken() was quoted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QUOTER

public static final char QUOTER
Our string quoting character.

INTRAQUOTER

public static final char INTRAQUOTER
Our character-quoting character within a string.

line

protected java.lang.String line
The string we are parsing.

len

protected int len
The length of the line being parsed.

pos

protected int pos
The position at which to start parsing on the next call to nextToken().

quoted

protected boolean quoted
True if the string most recently returned by nextToken() was a quoted string.
See Also:
wasQuoted()

qbuf

protected java.lang.StringBuffer qbuf
A buffer we use while parsing a quoted string.
Constructor Detail

QuoteTokenizer

public QuoteTokenizer()
Create a tokenizer.
See Also:
setInput(java.lang.String)

QuoteTokenizer

public QuoteTokenizer(java.lang.String line)
Create a tokenizer for a string.
Method Detail

setInput

public void setInput(java.lang.String line)
Set the string to be parsed.

nextToken

public java.lang.Object nextToken()
Return the next token. White space is used to separate tokens, but is not returned.
Returns:
The next token, or null if no more. If the string was quoted, the quotes are removed, and a flag is set so that a call to wasQuoted() will return true.

skipWhitespace

protected void skipWhitespace()
Skip white space.

isQuotedStart

protected boolean isQuotedStart(char c)
True if this character starts a quoted string.

isIdentifierStart

protected boolean isIdentifierStart(char c)
True if this character starts an identifier.

isIdentiferPart

protected boolean isIdentiferPart(char c)
True if this character can be in an identifier.

isNumberStart

protected boolean isNumberStart(char c)
True if this character starts a number.

isNumberPart

protected boolean isNumberPart(char c)
True if this character can be part of a number.

getQuoted

protected java.lang.String getQuoted()
Parse out a quoted string. pos points to the initial quote character.

getIdentifier

protected java.lang.String getIdentifier()
Parse out an identifier string. pos points to the initial character.

getNumber

protected java.lang.Number getNumber()
Get a number string. pos points to the initial digit.

stringToNumber

protected java.lang.Number stringToNumber(java.lang.String s)
Convert a string representation of a number to a Number.

wasQuoted

public boolean wasQuoted()
True if the string most recently returned by nextToken() was quoted.