    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

##

body
header
parser
previousSeparator

##

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

##

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

##

parser

     protected TokenCharacters parser

header

     protected String header

previousSeparator

     protected String previousSeparator

body

     protected StringBuffer body

##

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

##

setHeader

     public void setHeader(String message)

  Message is used as a comment at the begining of the string. Comment character is added to message.

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.

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.

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.

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