public final class PercentEscaper extends UnicodeEscaper
UnicodeEscaper that 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.
| 构造器和说明 |
|---|
PercentEscaper(String safeChars,
boolean plusForSpace)
Constructs a percent escaper with the specified safe characters and optional handling of the
space character.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected char[] |
escape(int cp)
Escapes the given Unicode code point in UTF-8.
|
String |
escape(String s)
Overridden for performance.
|
protected int |
nextEscapeIndex(CharSequence csq,
int index,
int end)
Overridden for performance.
|
codePointAt, escapeSlowpublic PercentEscaper(String safeChars, boolean plusForSpace)
Not that it is allowed, but not necessarily desirable to specify % as a safe
character. This has the effect of creating an escaper which has no well defined inverse but it
can be useful when escaping additional characters.
safeChars - a non null string specifying additional safe characters for this escaper (the
ranges 0..9, a..z and A..Z are always safe and should not be specified here)plusForSpace - true if ASCII space should be escaped to + rather than %20IllegalArgumentException - if any of the parameters were invalidprotected 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 scannedpublic String escape(String s)
escape 在接口中 Escaperescape 在类中 UnicodeEscapers - the literal string to be escapedstringprotected char[] escape(int cp)
escape 在类中 UnicodeEscapercp - the Unicode code point to escape if necessarynull if no escaping was neededCopyright © 2020. All rights reserved.