android.databinding.tool.util
Class SourceCodeEscapers

java.lang.Object
  extended by android.databinding.tool.util.SourceCodeEscapers

public final class SourceCodeEscapers
extends java.lang.Object

A factory for Escaper instances used to escape strings for safe use in various common programming languages.


Method Summary
static com.google.common.escape.Escaper javaCharEscaper()
          Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java character literal or string literal.
static com.google.common.escape.Escaper javaCharEscaperWithOctal()
          Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java character literal or string literal.
static com.google.common.escape.Escaper javaStringEscaperWithOctal()
          Returns an Escaper instance that escapes special characters in a string so it can safely be included in a Java string literal.
static com.google.common.escape.Escaper javaStringUnicodeEscaper()
          Returns an Escaper instance that replaces non-ASCII characters in a string with their Unicode escape sequences (\\uxxxx where xxxx is a hex number).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

javaCharEscaper

public static com.google.common.escape.Escaper javaCharEscaper()
Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java character literal or string literal. This is the preferred way to escape Java characters for use in String or character literals.

For more details, see Escape Sequences for Character and String Literals in The Java Language Specification.


javaCharEscaperWithOctal

public static com.google.common.escape.Escaper javaCharEscaperWithOctal()
Returns an Escaper instance that escapes special characters in a string so it can safely be included in either a Java character literal or string literal. The behavior of this escaper is the same as that of the javaStringEscaperWithOctal() except it also escapes single quotes.

Unlike javaCharEscaper() this escaper produces octal escape sequences (\nnn) for characters with values less than 256. While the escaped output can be shorter than when the standard Unicode escape sequence (\uxxxx) is used, the Java Language Specification discourages the use of octal for escaping Java strings. It is strongly recommended that, if possible, you use javaCharEscaper() in preference to this method.

For more details, see Escape Sequences for Character and String Literals in The Java Language Specification.


javaStringEscaperWithOctal

public static com.google.common.escape.Escaper javaStringEscaperWithOctal()
Returns an Escaper instance that escapes special characters in a string so it can safely be included in a Java string literal.

Note: Single quotes are not escaped, so it is not safe to use this escaper for escaping character literals.

Unlike javaCharEscaper() this escaper produces octal escape sequences (\nnn) for characters with values less than 256. While the escaped output can be shorter than when the standard Unicode escape sequence (\uxxxx) is used, the Java Language Specification discourages the use of octal for escaping Java strings. It is strongly recommended that, if possible, you use javaCharEscaper() in preference to this method.

For more details, see Escape Sequences for Character and String Literals in The Java Language Specification.


javaStringUnicodeEscaper

public static com.google.common.escape.Escaper javaStringUnicodeEscaper()
Returns an Escaper instance that replaces non-ASCII characters in a string with their Unicode escape sequences (\\uxxxx where xxxx is a hex number). Existing escape sequences won't be affected.

As existing escape sequences are not re-escaped, this escaper is idempotent. However this means that there can be no well defined inverse function for this escaper.

Note: the returned escaper is still a CharEscaper and will not combine surrogate pairs into a single code point before escaping.