org.jcoderz.commons.logging
Class StringEscapeFormat

java.lang.Object
  extended by java.text.Format
      extended by org.jcoderz.commons.logging.StringEscapeFormat
All Implemented Interfaces:
Serializable, Cloneable

public class StringEscapeFormat
extends Format

This formatter is used to escape chars in the source string with a configured escape char.The default escape char is '\'.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
Format.Field
 
Constructor Summary
StringEscapeFormat(String charsToEscape)
          Creates an instance of this, which will use the default escape char ESCAPE_CHAR.
StringEscapeFormat(String charsToEscape, char escapeChar)
          Creates an instance of this and sets the supplied escape char.
 
Method Summary
 StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
          Formats the supplied object by calling the object's toString() method and escaping the configured chars of this string with the configured escape char.
 Object parseObject(String source, ParsePosition pos)
           
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringEscapeFormat

public StringEscapeFormat(String charsToEscape)
Creates an instance of this, which will use the default escape char ESCAPE_CHAR.

Parameters:
charsToEscape - the characters which will be escaped by ESCAPE_CHAR.

StringEscapeFormat

public StringEscapeFormat(String charsToEscape,
                          char escapeChar)
Creates an instance of this and sets the supplied escape char.

Parameters:
charsToEscape - The characters which will be escaped by escapeChar.
escapeChar - The char by which to escape charToEscape. This must not be included in charsToEscape and must not be 0.
Throws:
IllegalArgumentException - if escapeChar is included within charsToEscape or is 0.
Method Detail

parseObject

public Object parseObject(String source,
                          ParsePosition pos)
Specified by:
parseObject in class Format
Parameters:
source - The string to parse.
pos - the position within source.
Returns:
the String being parsed from source with escape chars removed.
See Also:
Parses the source string. All characters configured as characters to escape are considered as delimiters (thus parsing is stopped at one of those) if they are not escaped with the configured character. A new string is created from this substring with all escape chars before an char to escape removed. Escape chars not being followed by a character to escape are not removed for the result string.

format

public StringBuffer format(Object obj,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Formats the supplied object by calling the object's toString() method and escaping the configured chars of this string with the configured escape char.

Specified by:
format in class Format
Parameters:
obj - the object to format.
toAppendTo - the StringBuffer where to append to the formatted string.
pos - the field position.
Returns:
StringBuffer where the formatted Object has been appended to.
See Also:
Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)


Copyright 2007 The jCoderZ Project.