public final class SourceCodeEscapers
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
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). |
public static com.google.common.escape.Escaper javaCharEscaper()
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.
public static com.google.common.escape.Escaper javaCharEscaperWithOctal()
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.
public static com.google.common.escape.Escaper javaStringEscaperWithOctal()
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.
public static com.google.common.escape.Escaper javaStringUnicodeEscaper()
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.