Package edu.wisc.library.ocfl.core.util
Class PercentEscaper
- java.lang.Object
-
- com.google.common.escape.Escaper
-
- com.google.common.escape.UnicodeEscaper
-
- edu.wisc.library.ocfl.core.util.PercentEscaper
-
@Beta @GwtCompatible public final class PercentEscaper extends com.google.common.escape.UnicodeEscaperNOTICE: This class is copied from Guava 28.2-jre and modified to support lowercase hex encoding and either encoding all characters not in a given set or encoding only the characters in a given set by Peter Winckles.A
UnicodeEscaperthat escapes some set of Java characters using a UTF-8 based percent encoding scheme. The set of safe characters (those which remain unescaped) can be specified on construction.This class is primarily used for creating URI escapers in
UrlEscapersbut can be used directly if required. While URI escapers impose specific semantics on which characters are considered 'safe', this class has a minimal set of restrictions.When escaping a String, the following rules apply:
- All specified safe characters remain unchanged.
- If
plusForSpacewas specified, the space character " " is converted into a plus sign"+". - All other characters are converted into one or more bytes using UTF-8 encoding and each byte is then represented by the 3-character string "%XX", where "XX" is the two-digit, uppercase, hexadecimal representation of the byte value.
For performance reasons the only currently supported character encoding of this class is UTF-8.
Note: This escaper produces uppercase hexadecimal sequences.
- Since:
- 15.0
- Author:
- David Beaumont
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPercentEscaper.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PercentEscaper.Builderbuilder()Creates a builder without any safe or unsafe characters set.static PercentEscaper.BuilderbuilderWithSafeAlphaNumeric()Creates a builder with safe alpha numeric characters preconfigured.protected char[]escape(int cp)Escapes the given Unicode code point in UTF-8.Stringescape(String s)protected intnextEscapeIndex(CharSequence csq, int index, int end)
-
-
-
Method Detail
-
builder
public static PercentEscaper.Builder builder()
Creates a builder without any safe or unsafe characters set.- Returns:
- builder
-
builderWithSafeAlphaNumeric
public static PercentEscaper.Builder builderWithSafeAlphaNumeric()
Creates a builder with safe alpha numeric characters preconfigured.- Returns:
- builder
-
nextEscapeIndex
protected int nextEscapeIndex(CharSequence csq, int index, int end)
- Overrides:
nextEscapeIndexin classcom.google.common.escape.UnicodeEscaper
-
escape
public String escape(String s)
- Overrides:
escapein classcom.google.common.escape.UnicodeEscaper
-
escape
protected char[] escape(int cp)
Escapes the given Unicode code point in UTF-8.- Specified by:
escapein classcom.google.common.escape.UnicodeEscaper
-
-