Package com.google.common.escape
Class Escapers
- java.lang.Object
-
- com.google.common.escape.Escapers
-
public final class Escapers extends java.lang.ObjectStatic utility methods pertaining toEscaperinstances.- Since:
- 15.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEscapers.BuilderA builder for simple, fast escapers.
-
Field Summary
Fields Modifier and Type Field Description private static EscaperNULL_ESCAPER
-
Constructor Summary
Constructors Modifier Constructor Description privateEscapers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static UnicodeEscaperasUnicodeEscaper(Escaper escaper)Returns aUnicodeEscaperequivalent to the given escaper instance.static Escapers.Builderbuilder()Returns a builder for creating simple, fast escapers.static java.lang.StringcomputeReplacement(CharEscaper escaper, char c)Returns a string that would replace the given character in the specified escaper, ornullif no replacement should be made.static java.lang.StringcomputeReplacement(UnicodeEscaper escaper, int cp)Returns a string that would replace the given character in the specified escaper, ornullif no replacement should be made.static EscapernullEscaper()Returns anEscaperthat does no escaping, passing all character data through unchanged.private static java.lang.StringstringOrNull(char[] in)private static UnicodeEscaperwrap(CharEscaper escaper)Private helper to wrap a CharEscaper as a UnicodeEscaper.
-
-
-
Field Detail
-
NULL_ESCAPER
private static final Escaper NULL_ESCAPER
-
-
Method Detail
-
nullEscaper
public static Escaper nullEscaper()
Returns anEscaperthat does no escaping, passing all character data through unchanged.
-
builder
public static Escapers.Builder builder()
Returns a builder for creating simple, fast escapers. A builder instance can be reused and each escaper that is created will be a snapshot of the current builder state. Builders are not thread safe.The initial state of the builder is such that:
- There are no replacement mappings
safeMin == Character.MIN_VALUEsafeMax == Character.MAX_VALUEunsafeReplacement == null
For performance reasons escapers created by this builder are not Unicode aware and will not validate the well-formedness of their input.
-
asUnicodeEscaper
static UnicodeEscaper asUnicodeEscaper(Escaper escaper)
Returns aUnicodeEscaperequivalent to the given escaper instance. If the escaper is already a UnicodeEscaper then it is simply returned, otherwise it is wrapped in a UnicodeEscaper.When a
CharEscaperescaper is wrapped by this method it acquires extra behavior with respect to the well-formedness of Unicode character sequences and will throwIllegalArgumentExceptionwhen given bad input.- Parameters:
escaper- the instance to be wrapped- Returns:
- a UnicodeEscaper with the same behavior as the given instance
- Throws:
java.lang.NullPointerException- if escaper is nulljava.lang.IllegalArgumentException- if escaper is not a UnicodeEscaper or a CharEscaper
-
computeReplacement
public static java.lang.String computeReplacement(CharEscaper escaper, char c)
Returns a string that would replace the given character in the specified escaper, ornullif no replacement should be made. This method is intended for use in tests through theEscaperAssertsclass; production users ofCharEscapershould limit themselves to its public interface.- Parameters:
c- the character to escape if necessary- Returns:
- the replacement string, or
nullif no escaping was needed
-
computeReplacement
public static java.lang.String computeReplacement(UnicodeEscaper escaper, int cp)
Returns a string that would replace the given character in the specified escaper, ornullif no replacement should be made. This method is intended for use in tests through theEscaperAssertsclass; production users ofUnicodeEscapershould limit themselves to its public interface.- Parameters:
cp- the Unicode code point to escape if necessary- Returns:
- the replacement string, or
nullif no escaping was needed
-
stringOrNull
private static java.lang.String stringOrNull(char[] in)
-
wrap
private static UnicodeEscaper wrap(CharEscaper escaper)
Private helper to wrap a CharEscaper as a UnicodeEscaper.
-
-