-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Perform an HTML5 level 2 (result is ASCII) escape operation on aString
input.static String
Perform a JSON level 2 (basic set and all non-ASCII chars) escape operation on aString
input.static String
Perform am URI path escape operation on aString
input usingUTF-8
as encoding.
-
Method Details
-
uri
Perform am URI path escape operation on aString
input usingUTF-8
as encoding.The following are the only allowed chars in an URI path (will not be escaped):
A-Z a-z 0-9
- . _ ~
! $ & ' ( ) * + , ; =
: @
/
All other chars will be escaped by converting them to the sequence of bytes that represents them in the
UTF-8
and then representing each byte in%HH
syntax, beingHH
the hexadecimal representation of the byte.This method is thread-safe.
- Parameters:
value
- theString
to be escaped.- Returns:
- The escaped result
String
. As a memory-performance improvement, will return the exact same object as thetext
input argument if no escaping modifications were required (and no additionalString
objects will be created during processing). Will returnnull
if input isnull
.
-
html
Perform an HTML5 level 2 (result is ASCII) escape operation on aString
input.Level 2 means this method will escape:
- The five markup-significant characters:
<
,>
,&
,"
and'
- All non ASCII characters.
This escape will be performed by replacing those chars by the corresponding HTML5 Named Character References (e.g.
'´'
) when such NCR exists for the replaced character, and replacing by a decimal character reference (e.g.'ₙ'
) when there is no NCR for the replaced character.This method is thread-safe.
- Parameters:
value
- theString
to be escaped.- Returns:
- The escaped result
String
. As a memory-performance improvement, will return the exact same object as thetext
input argument if no escaping modifications were required (and no additionalString
objects will be created during processing). Will returnnull
if input isnull
.
- The five markup-significant characters:
-
json
Perform a JSON level 2 (basic set and all non-ASCII chars) escape operation on aString
input.Level 2 means this method will escape:
- The JSON basic escape set:
- The Single Escape Characters:
\b
(U+0008
),\t
(U+0009
),\n
(U+000A
),\f
(U+000C
),\r
(U+000D
),\"
(U+0022
),\\
(U+005C
) and\/
(U+002F
). Note that\/
is optional, and will only be used when the/
symbol appears after<
, as in</
. This is to avoid accidentally closing<script>
tags in HTML. - Two ranges of non-displayable, control characters (some of which are already part
of the single escape characters list):
U+0000
toU+001F
(required by the JSON spec) andU+007F
toU+009F
(additional).
- The Single Escape Characters:
- All non ASCII characters.
This escape will be performed by using the Single Escape Chars whenever possible. For escaped characters that do not have an associated SEC, default to
\uFFFF
Hexadecimal Escapes.This method is thread-safe.
- Parameters:
value
- theString
to be escaped.- Returns:
- The escaped result
String
. As a memory-performance improvement, will return the exact same object as thetext
input argument if no escaping modifications were required (and no additionalString
objects will be created during processing). Will returnnull
if input isnull
.
- The JSON basic escape set:
-