sdsu.util
Class Stringizer

java.lang.Object
  |
  +--sdsu.util.Stringizer

public class Stringizer
extends java.lang.Object

This class aids in creating parsable strings. This is useful in producing a ascii representations of objects. Strings produced via Stringizer can be parsed by SimpleTokenizer. A string contains tokens, comments, and separators. Comments start with the comment character and continue to the next newline (\n ) character. A token can be any object convertable to a string via toString(). If string representation of the token contains the separator, whitespace, or comment character it automatically quoted. Quote characters and escape characters in the string representation are automatically escaped (preceeded by the escape character. Whitespace characters are used only for quoting tokens. The separator given with the token is added to string only when the next token is appended.

Version:
1.0 2 February 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
SimpleTokenizer

Constructor Summary
Stringizer(int size, TokenCharacters parser)
          Create a Stringizer with initial room for size tokens
Stringizer(TokenCharacters parser)
          Create a Stringizer
 
Method Summary
 void appendComment(java.lang.String message)
          Appends message as a comment at current location in string.
 void appendToken(java.lang.Object token, char separator)
          Appends token to the end of the string.
 void appendToken(java.lang.Object token, java.lang.String separator)
          Appends token to the end of the string.
 void setHeader(java.lang.String message)
          Message is used as a comment at the begining of the string.
 java.lang.String toString()
          Returns the string built up via the Stringizer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Stringizer

public Stringizer(TokenCharacters parser)
Create a Stringizer

Stringizer

public Stringizer(int size,
                  TokenCharacters parser)
Create a Stringizer with initial room for size tokens
Parameters:
commentChar - character used to indicate start of a comment
beginQuoteChar - character used to start a quote of a string containing special characters
endQuoteChar - character used to end a quote of a string containing special characters
quotableChars - characters that need to be quoted. Use null or empty string for none
Method Detail

setHeader

public void setHeader(java.lang.String message)
Message is used as a comment at the begining of the string. Comment character is added to message.

appendComment

public void appendComment(java.lang.String message)
Appends message as a comment at current location in string. Comment character and newline added to message so message can be parsed.

appendToken

public void appendToken(java.lang.Object token,
                        char separator)
Appends token to the end of the string. Token object is converted to a string via toString(). If string representation contains the separator, quotableChars, comment character it automatically quoted. Separator is appended to string only if this is not the last token to be added to the string. Separator is to used to parse string back into tokens.

appendToken

public void appendToken(java.lang.Object token,
                        java.lang.String separator)
Appends token to the end of the string. Token object is converted to a string via toString(). If string representation contains the separator, quotableChars, comment character it automatically quoted. Separator is appended to string only if this is not the last token to be added to the string. Separator is to used to parse string back into tokens. Whitespace can be added to separator to make string more readable.

toString

public java.lang.String toString()
Returns the string built up via the Stringizer. If present, a header is added.
Overrides:
toString in class java.lang.Object