edu.rice.cs.javalanglevels
Class CharConverter

java.lang.Object
  extended by edu.rice.cs.javalanglevels.CharConverter

public abstract class CharConverter
extends Object

A class full of static methods for escaping/unescaping characters. It's abstract because it should not be instantiated.


Constructor Summary
CharConverter()
           
 
Method Summary
static String escapeChar(char c)
          Escapes the given char to be suitable for writing out in a Java char or String literal.
static void escapeChar(char c, StringBuffer buf)
          Escapes the given char to be suitable for writing out in a Java char or String literal.
static String escapeString(String s)
          Escapes the given String to be suitable for writing out as a Java String literal.
static char unescapeChar(String in)
          Unescapes the given string, escaped as it would be in Java source, to a single char.
static String unescapeString(String in)
          Unescapes the given string, escaped as it would be in Java source, to a String.
static int unescapeString(String in, int startPos, StringBuffer out)
          Unescapes one character in the given string, escaped as it would be in Java source, to a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharConverter

public CharConverter()
Method Detail

escapeChar

public static String escapeChar(char c)
Escapes the given char to be suitable for writing out in a Java char or String literal.

Parameters:
c - Character to escape
Returns:
A string consisting of c, properly escaped for use inside a Java char or String literal. There are no quotation marks around the result.

escapeChar

public static void escapeChar(char c,
                              StringBuffer buf)
Escapes the given char to be suitable for writing out in a Java char or String literal.

Parameters:
c - Character to escape
buf - StringBuffer where the result is written out

escapeString

public static String escapeString(String s)
Escapes the given String to be suitable for writing out as a Java String literal.

Parameters:
s - String to escape
Returns:
A string consisting of s, properly escaped for use inside a Java String literal. There are no quotation marks around the result.

unescapeChar

public static char unescapeChar(String in)
Unescapes the given string, escaped as it would be in Java source, to a single char. Note that this does not handle unicode escapes of the form \ uXXXX; these are expected to have already been processed out of the input string. The only escapes that are handled are octal escapes and \n \t \b \r \f \\ \' \".

Parameters:
in - String containing (possibly) escaped character, without quotes
Returns:
char value of the input string, unescaped.

unescapeString

public static String unescapeString(String in)
Unescapes the given string, escaped as it would be in Java source, to a String. Note that this does not handle unicode escapes of the form \ uXXXX; these are expected to have already been processed out of the input string. The only escapes that are handled are octal escapes and \n \t \b \r \f \\ \' \".

Parameters:
in - String containing (possibly) escaped characters, without quotes
Returns:
Unescaped string value of the input string

unescapeString

public static int unescapeString(String in,
                                 int startPos,
                                 StringBuffer out)
Unescapes one character in the given string, escaped as it would be in Java source, to a String. Note that this does not handle unicode escapes of the form \ uXXXX; these are expected to have already been processed out of the input string. The only escapes that are handled are octal escapes and \n \t \b \r \f \\ \' \".

Parameters:
in - String containing (possibly) escaped characters
startPos - Starting position of the next character to unescape
out - StringBuffer to write out the unescaped character to.
Returns:
Position after the end of the parsed character