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 UrlEscapers but 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:
plusForSpace was specified, the space character " " is converted into a plus
sign "+".
For performance reasons the only currently supported character encoding of this class is UTF-8.
Note
This escaper produces uppercase hexadecimal sequences.
This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | DEST_PAD
The amount of padding (chars) to use when growing the escape buffer. |
| private static final String | |
| private static final boolean[] | safeOctets
An array of flags where for any |
| private static final char[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static int | Returns: the Unicode code point for the given index or the negated value of the trailing high surrogate character at the end of the sequencethe sequence of characters from which to decode the code point seq, int the index of the first character to decode index, int the index beyond the last valid character to decode end)Returns the Unicode code point of the character at the given index. |
| public static PercentEscaper | |
| private static boolean[] | createSafeOctets(String safeChars)
Creates a boolean array with entries corresponding to the character values specified in safeChars set to true. |
| public String | |
| private static char[] | |
| private static String | Returns: the escaped form ofstringthe literal string to be escaped s, int the index to start escaping from index)Returns the escaped form of a given literal string, starting at the given index. |
| private static char[] | growBuffer(char[] dest, int index, int size)
Helper method to grow the character buffer as needed, this only happens once in a while so it's ok if it's in a method call. |
| private static int |
| DEST_PAD | back to summary |
|---|---|
| private static final int DEST_PAD The amount of padding (chars) to use when growing the escape buffer. | |
| SAFE_CHARS | back to summary |
|---|---|
| private static final String SAFE_CHARS | |
| safeOctets | back to summary |
|---|---|
| private static final boolean[] safeOctets An array of flags where for any | |
| UPPER_HEX_DIGITS | back to summary |
|---|---|
| private static final char[] UPPER_HEX_DIGITS | |
| PercentEscaper | back to summary |
|---|---|
| public PercentEscaper() | |
| codePointAt | back to summary |
|---|---|
| private static int codePointAt(CharSequence seq, int index, int end) Returns the Unicode code point of the character at the given index. Unlike The behaviour of this method is as follows:
| |
| create | back to summary |
|---|---|
| public static PercentEscaper create() The default | |
| createSafeOctets | back to summary |
|---|---|
| private static boolean[] createSafeOctets(String safeChars) Creates a boolean array with entries corresponding to the character values specified in safeChars set to true. The array is as small as is required to hold the given character information. | |
| escape | back to summary |
|---|---|
| public String escape(String s) Escape the provided String, using percent-style URL Encoding. | |
| escape | back to summary |
|---|---|
| private static char[] escape(int cp) Escapes the given Unicode code point in UTF-8.
| |
| escapeSlow | back to summary |
|---|---|
| private static String escapeSlow(String s, int index) Returns the escaped form of a given literal string, starting at the given index. This method is
called by the This method is not reentrant and may only be invoked by the top level
| |
| growBuffer | back to summary |
|---|---|
| private static char[] growBuffer(char[] dest, int index, int size) Helper method to grow the character buffer as needed, this only happens once in a while so it's ok if it's in a method call. If the index passed in is 0 then no copying will be done. | |
| nextEscapeIndex | back to summary |
|---|---|
| private static int nextEscapeIndex(CharSequence csq, int index, int end) | |