Class SourceCodeEscapers
- java.lang.Object
-
- android.databinding.tool.util.SourceCodeEscapers
-
public final class SourceCodeEscapers extends java.lang.ObjectA factory for Escaper instances used to escape strings for safe use in various common programming languages.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.google.common.escape.EscaperjavaCharEscaper()Returns anEscaperinstance 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.EscaperjavaCharEscaperWithOctal()Returns anEscaperinstance 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.EscaperjavaStringEscaperWithOctal()Returns anEscaperinstance that escapes special characters in a string so it can safely be included in a Java string literal.static com.google.common.escape.EscaperjavaStringUnicodeEscaper()Returns anEscaperinstance that replaces non-ASCII characters in a string with their Unicode escape sequences (\\uxxxxwherexxxxis a hex number).
-
-
-
Method Detail
-
javaCharEscaper
public static com.google.common.escape.Escaper javaCharEscaper()
Returns anEscaperinstance 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 anEscaperinstance 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 thejavaStringEscaperWithOctal()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 usejavaCharEscaper()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 anEscaperinstance 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 usejavaCharEscaper()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 anEscaperinstance that replaces non-ASCII characters in a string with their Unicode escape sequences (\\uxxxxwherexxxxis 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
CharEscaperand will not combine surrogate pairs into a single code point before escaping.
-
-