Package com.google.common.escape
Class Escapers
- java.lang.Object
-
- com.google.common.escape.Escapers
-
@GwtCompatible public final class Escapers extends Object
Static utility methods pertaining toEscaper
instances.- Since:
- 15.0
- Author:
- Sven Mawson, David Beaumont
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Escapers.Builder
A builder for simple, fast escapers.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Escapers.Builder
builder()
Returns a builder for creating simple, fast escapers.static @Nullable String
computeReplacement(CharEscaper escaper, char c)
Returns a string that would replace the given character in the specified escaper, ornull
if no replacement should be made.static @Nullable String
computeReplacement(UnicodeEscaper escaper, int cp)
Returns a string that would replace the given character in the specified escaper, ornull
if no replacement should be made.static Escaper
nullEscaper()
Returns anEscaper
that does no escaping, passing all character data through unchanged.
-
-
-
Method Detail
-
nullEscaper
public static Escaper nullEscaper()
Returns anEscaper
that 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_VALUE
safeMax == Character.MAX_VALUE
unsafeReplacement == null
For performance reasons escapers created by this builder are not Unicode aware and will not validate the well-formedness of their input.
-
computeReplacement
public static @Nullable String computeReplacement(CharEscaper escaper, char c)
Returns a string that would replace the given character in the specified escaper, ornull
if no replacement should be made. This method is intended for use in tests through theEscaperAsserts
class; production users ofCharEscaper
should limit themselves to its public interface.- Parameters:
c
- the character to escape if necessary- Returns:
- the replacement string, or
null
if no escaping was needed
-
computeReplacement
public static @Nullable String computeReplacement(UnicodeEscaper escaper, int cp)
Returns a string that would replace the given character in the specified escaper, ornull
if no replacement should be made. This method is intended for use in tests through theEscaperAsserts
class; production users ofUnicodeEscaper
should limit themselves to its public interface.- Parameters:
cp
- the Unicode code point to escape if necessary- Returns:
- the replacement string, or
null
if no escaping was needed
-
-