| java.lang.Object | ||
| ↳ | com.google.gdata.util.common.base.UnicodeEscaper | |
| ↳ | com.google.gdata.util.common.base.PercentEscaper | |
A UnicodeEscaper that escapes some set of Java characters using
the URI percent encoding scheme. The set of safe characters (those which
remain unescaped) can be specified on construction.
For details on escaping URIs for use in web pages, see section 2.4 of RFC 3986.
In most cases this class should not need to be used directly. If you
have no special requirements for escaping your URIs, you should use either
uriEscaper() or
uriEscaper(boolean).
When encoding a String, the following rules apply:
plusForSpace was specified, the space character " " is
converted into a plus sign "+".
RFC 2396 specifies the set of unreserved characters as "-", "_", ".", "!", "~", "*", "'", "(" and ")". It goes on to state:
Unreserved characters can be escaped without changing the semantics of the URI, but this should not be done unless the URI is being used in a context that does not allow the unescaped character to appear.
For performance reasons the only currently supported character encoding of this class is UTF-8.
Note: This escaper produces uppercase hexidecimal sequences. From
RFC 3986:
"URI producers and normalizers should use uppercase hexadecimal digits
for all percent-encodings."
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | SAFECHARS_URLENCODER | A string of safe characters that mimics the behavior of java.net.URLEncoder. | |||||||||
| String | SAFEPATHCHARS_URLENCODER | A string of characters that do not need to be encoded when used in URI path segments, as specified in RFC 3986. | |||||||||
| String | SAFEQUERYSTRINGCHARS_URLENCODER | A string of characters that do not need to be encoded when used in URI query strings, as specified in RFC 3986. | |||||||||
|
[Expand]
Inherited Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.gdata.util.common.base.UnicodeEscaper
| |||||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| UPPER_HEX_DIGITS | |||||||||||
| URI_ESCAPED_SPACE | |||||||||||
| plusForSpace | If true we should convert space to the + character. |
||||||||||
| safeOctets | An array of flags where for any char c if safeOctets[c] is
true then c should remain unmodified in the output. |
||||||||||
|
[Expand]
Inherited Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.gdata.util.common.base.UnicodeEscaper
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a URI escaper with the specified safe characters and optional
handling of the space character.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Returns the escaped form of a given literal string.
| |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Escapes the given Unicode code point in UTF-8.
| |||||||||||
Scans a sub-sequence of characters from a given CharSequence,
returning the index of the next character that requires escaping.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
com.google.gdata.util.common.base.UnicodeEscaper
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
com.google.gdata.util.common.base.Escaper
| |||||||||||
A string of safe characters that mimics the behavior of java.net.URLEncoder.
A string of characters that do not need to be encoded when used in URI path segments, as specified in RFC 3986. Note that some of these characters do need to be escaped when used in other parts of the URI.
A string of characters that do not need to be encoded when used in URI query strings, as specified in RFC 3986. Note that some of these characters do need to be escaped when used in other parts of the URI.
If true we should convert space to the + character.
An array of flags where for any char c if safeOctets[c] is
true then c should remain unmodified in the output. If
c > safeOctets.length then it should be escaped.
Constructs a URI escaper with the specified safe characters and optional handling of the space character.
| 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 %20 |
| IllegalArgumentException | if any of the parameters were invalid |
|---|
Returns the escaped form of a given literal string.
If you are escaping input in arbitrary successive chunks, then it is not
generally safe to use this method. If an input string ends with an
unmatched high surrogate character, then this method will throw
IllegalArgumentException. You should either ensure your input is
valid UTF-16 before
calling this method or use an escaped Appendable (as returned by
escape(Appendable)) which can cope with arbitrarily split input.
Note: When implementing an escaper it is a good idea to override
this method for efficiency by inlining the implementation of
nextEscapeIndex(CharSequence, int, int) directly. Doing this for
PercentEscaper more than doubled the performance for unescaped
strings (as measured by CharEscapersBenchmark).
| s | The literal string to be escaped |
|---|
stringEscapes the given Unicode code point in UTF-8.
| cp | The Unicode code point to escape if necessary |
|---|
null if no escaping was
needed
Scans a sub-sequence of characters from a given CharSequence, returning the index of the next character that requires escaping.
Note: When implementing an escaper, it is a good idea to override
this method for efficiency. The base class implementation determines
successive Unicode code points and invokes escape(int) for each of
them. If the semantics of your escaper are such that code points in the
supplementary range are either all escaped or all unescaped, this method
can be implemented more efficiently using charAt(int).
Note however that if your escaper does not escape characters in the supplementary range, you should either continue to validate the correctness of any surrogate characters encountered or provide a clear warning to users that your escaper does not validate its input.
See PercentEscaper for an example.
| csq | A sequence of characters |
|---|---|
| index | The index of the first character to be scanned |
| end | The index immediately after the last character to be scanned |