public abstract class ArrayBasedUnicodeEscaper extends UnicodeEscaper
UnicodeEscaper that uses an array to quickly look up replacement characters for a given
code point. An additional safe range is provided that determines whether code points without
specific replacements are to be considered safe and left unescaped or should be escaped in a
general way.
A good example of usage of this class is for HTML escaping where the replacement array
contains information about the named HTML entities such as & and " while
escapeUnsafe(int) is overridden to handle general escaping of the form &#NNNNN;.
The size of the data structure used by ArrayBasedUnicodeEscaper is proportional to the
highest valued code point that requires escaping. For example a replacement map containing the
single character '\u1000' will require approximately 16K of memory. If you need
to create multiple escaper instances that have the same character replacement mapping consider
using ArrayBasedEscaperMap.
| 限定符 | 构造器和说明 |
|---|---|
protected |
ArrayBasedUnicodeEscaper(ArrayBasedEscaperMap escaperMap,
int safeMin,
int safeMax,
String unsafeReplacement)
Creates a new ArrayBasedUnicodeEscaper instance with the given replacement map and specified
safe range.
|
protected |
ArrayBasedUnicodeEscaper(Map<Character,String> replacementMap,
int safeMin,
int safeMax,
String unsafeReplacement)
Creates a new ArrayBasedUnicodeEscaper instance with the given replacement map and specified
safe range.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected char[] |
escape(int cp)
Escapes a single Unicode code point using the replacement array and safe range values.
|
String |
escape(String s)
This is overridden to improve performance.
|
protected abstract char[] |
escapeUnsafe(int cp)
Escapes a code point that has no direct explicit value in the replacement array and lies
outside the stated safe range.
|
protected int |
nextEscapeIndex(CharSequence csq,
int index,
int end)
Overridden for performance.
|
codePointAt, escapeSlowprotected ArrayBasedUnicodeEscaper(Map<Character,String> replacementMap, int safeMin, int safeMax, @Nullable String unsafeReplacement)
safeMax < safeMin then no code points are considered safe.
If a code point has no mapped replacement then it is checked against the safe range. If it
lies outside that, then escapeUnsafe(int) is called, otherwise no escaping is performed.
replacementMap - a map of characters to their escaped representationssafeMin - the lowest character value in the safe rangesafeMax - the highest character value in the safe rangeunsafeReplacement - the default replacement for unsafe characters or null if no default
replacement is requiredprotected ArrayBasedUnicodeEscaper(ArrayBasedEscaperMap escaperMap, int safeMin, int safeMax, @Nullable String unsafeReplacement)
safeMax < safeMin then no code points are considered safe. This
initializer is useful when explicit instances of ArrayBasedEscaperMap are used to allow the
sharing of large replacement mappings.
If a code point has no mapped replacement then it is checked against the safe range. If it
lies outside that, then escapeUnsafe(int) is called, otherwise no escaping is performed.
escaperMap - the map of replacementssafeMin - the lowest character value in the safe rangesafeMax - the highest character value in the safe rangeunsafeReplacement - the default replacement for unsafe characters or null if no default
replacement is requiredpublic final String escape(String s)
escape 在接口中 Escaperescape 在类中 UnicodeEscapers - the literal string to be escapedstringprotected final char[] escape(int cp)
escapeUnsafe(int) is called.escape 在类中 UnicodeEscapercp - the Unicode code point to escape if necessarynull if no escaping was neededprotected final int nextEscapeIndex(CharSequence csq, int index, int end)
nextEscapeIndex 在类中 UnicodeEscapercsq - a sequence of charactersindex - the index of the first character to be scannedend - the index immediately after the last character to be scannedprotected abstract char[] escapeUnsafe(int cp)
Note that arrays returned by this method must not be modified once they have been returned. However it is acceptable to return the same array multiple times (even for different input characters).
cp - the Unicode code point to escapenull if no escaping was requiredCopyright © 2022. All rights reserved.