randoop.util
Class StringEscapeUtils

Object
  extended by StringEscapeUtils

public class StringEscapeUtils
extends Object

Escapes and unescapes Strings for Java, Java Script, HTML, XML, and SQL.

Since:
2.0

Constructor Summary
Constructor and Description
StringEscapeUtils()
          StringEscapeUtils instances should NOT be constructed in standard programming.
 
Method Summary
Modifier and Type Method and Description
static String escapeJava(String str)
          Escapes the characters in a String using Java String rules.
static void escapeJava(Writer out, String str)
          Escapes the characters in a String using Java String rules to a Writer.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringEscapeUtils

public StringEscapeUtils()

StringEscapeUtils instances should NOT be constructed in standard programming.

Instead, the class should be used as:

StringEscapeUtils.escapeJava("foo");

This constructor is public to permit tools that require a JavaBean instance to operate.

Method Detail

escapeJava

public static String escapeJava(String str)

Escapes the characters in a String using Java String rules.

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't'.

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote must be escaped.

Example:

 input string: He didn't say, "Stop!"
 output string: He didn't say, \"Stop!\"
 

Parameters:
str - String to escape values in, may be null
Returns:
String with escaped values, null if null string input

escapeJava

public static void escapeJava(Writer out,
                              String str)
                       throws IOException

Escapes the characters in a String using Java String rules to a Writer.

A null string input has no effect.

Parameters:
out - Writer to write escaped string into
str - String to escape values in, may be null
Throws:
IllegalArgumentException - if the Writer is null
IOException - if error occurs on underlying Writer
See Also:
escapeJava(java.lang.String)