com.ibm.commons.util
Class TextUtil

java.lang.Object
  extended by com.ibm.commons.util.TextUtil

public final class TextUtil
extends java.lang.Object

Text utilities.


Constructor Summary
TextUtil()
           
 
Method Summary
static java.lang.String fromJavaString(java.lang.String s)
          Convert a Java source string to a regular string.
static java.lang.String fromXMLString(java.lang.String s)
          Converts a XML string with internal entities into a Java string.
static java.lang.String indentString(java.lang.String s, java.lang.String indent)
          Add a string before each row of an existing string.
static java.lang.String toJavaString(java.lang.String s, boolean addQuotes)
          Format a string to be a JavaSource string.
static java.lang.String toXMLString(java.lang.String s)
          Converts a Java string to an XML one, with internal entities into a Java string.
static java.lang.String toXMLString(java.lang.String s, boolean ascii)
          Converts a Java string to an XML one, with internal entities into a Java string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtil

public TextUtil()
Method Detail

indentString

public static java.lang.String indentString(java.lang.String s,
                                            java.lang.String indent)
Add a string before each row of an existing string.

This function may be used by code generators in order to properly indent code. To be consistent with Reader's behavior, a line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r) or a carriage return immediately followed by a linefeed. In each case, the end of line characters are preserved as they are.


fromJavaString

public static java.lang.String fromJavaString(java.lang.String s)
Convert a Java source string to a regular string.

This replace all the escape sequences by the actual characters.


toJavaString

public static java.lang.String toJavaString(java.lang.String s,
                                            boolean addQuotes)
Format a string to be a JavaSource string.

This replace all the special characters by escape sequences.


fromXMLString

public static java.lang.String fromXMLString(java.lang.String s)
Converts a XML string with internal entities into a Java string.

The entities parsed are

Parameters:
s - the XML string
Returns:
the converted string

toXMLString

public static java.lang.String toXMLString(java.lang.String s)
Converts a Java string to an XML one, with internal entities into a Java string.

The entities parsed are

Parameters:
s - the Java string
Returns:
the converted string

toXMLString

public static java.lang.String toXMLString(java.lang.String s,
                                           boolean ascii)
Converts a Java string to an XML one, with internal entities into a Java string. The entities parsed are

Parameters:
s - the Java string
ascii - ensure that all the character are in the ascii range, else they will be replaced by an entity
Returns:
the converted string