All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.util.Stringizer

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

public class Stringizer
extends 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.

Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
SimpleTokenizer

Variable Index

 o body
 o header
 o parser
 o previousSeparator

Constructor Index

 o Stringizer(int, TokenCharacters)
Create a Stringizer with initial room for size tokens
 o Stringizer(TokenCharacters)
Create a Stringizer

Method Index

 o appendComment(String)
Appends message as a comment at current location in string.
 o appendToken(Object, char)
Appends token to the end of the string.
 o appendToken(Object, String)
Appends token to the end of the string.
 o setHeader(String)
Message is used as a comment at the begining of the string.
 o toString()
Returns the string built up via the Stringizer.

Variables

 o parser
 protected TokenCharacters parser
 o header
 protected String header
 o previousSeparator
 protected String previousSeparator
 o body
 protected StringBuffer body

Constructors

 o Stringizer
 public Stringizer(TokenCharacters parser)
Create a Stringizer

 o 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

Methods

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

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

 o appendToken
 public void appendToken(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.

 o appendToken
 public void appendToken(Object token,
                         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.

 o toString
 public String toString()
Returns the string built up via the Stringizer. If present, a header is added.

Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index