Package org.cthing.escapers
Class HtmlEscaper
java.lang.Object
org.cthing.escapers.HtmlEscaper
Escapes string and character arrays using numeric and named HTML character entities. Markup-significant characters
(e.g. <) are always escaped. Options are provided to escape additional characters using numeric or named
character entities. Characters are escaped according to the following table:
| Code Point | Escape | Description |
|---|---|---|
| 0x09 | Unchanged | Tab |
| 0x0A | Unchanged | Line feed |
| 0x0D | Unchanged | Carriage return |
| 0x20 - 0x21 | Unchanged | Printable ASCII characters |
| 0x22 | " | Double quote |
| 0x23 - 0x25 | Unchanged | Printable ASCII characters |
| 0x26 | & | Ampersand |
| 0x27 | ' | Single quote |
| 0x28 - 0x3B | Unchanged | Printable ASCII characters |
| 0x3C | < | Less than |
| 0x3D | Unchanged | Printable ASCII characters |
| 0x3E | > | Greater than |
| 0x3F - 0x7E | Unchanged | Printable ASCII characters |
| 0x7F | Numeric character entity (e.g. ) | ASCII control character |
| 0x80 - 0xFF |
Unchanged by default or numeric character entity (e.g. „)
if HtmlEscaper.Option.ESCAPE_NON_ASCII specified, or named character entity (e.g. ®)
if HtmlEscaper.Option.USE_ISO_LATIN_1_ENTITIES specified.
|
ISO Latin-1 |
| 0x100 - 0xD7FF |
Unchanged by default or numeric character entity (e.g. )
if HtmlEscaper.Option.ESCAPE_NON_ASCII specified, or named character entity (e.g. δ)
if HtmlEscaper.Option.USE_HTML4_EXTENDED_ENTITIES specified.
|
Unicode BMP |
| 0xE000 - 0xFFFD |
Unchanged by default or numeric character entity (e.g. )
if HtmlEscaper.Option.ESCAPE_NON_ASCII specified
|
Unicode BMP |
| 0x10000 - 0x10FFFF |
Unchanged by default or numeric character entity (e.g. 𐀀)
if HtmlEscaper.Option.ESCAPE_NON_ASCII specified
|
Unicode surrogate pairs |
Characters not listed in the above table are not included in the output (e.g. the null character 0x00 is dropped).
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidescape(char[] charArr, int offset, int length, Writer writer, Set<HtmlEscaper.Option> options) Applies HTML escaping to the specified character array and writes the result to the specified writer.static voidescape(char[] charArr, int offset, int length, Writer writer, HtmlEscaper.Option... options) Applies HTML escaping to the specified character array and writes the result to the specified writer.static Stringescape(char[] charArr, int offset, int length, Set<HtmlEscaper.Option> options) Applies HTML escaping to the specified character array.static Stringescape(char[] charArr, int offset, int length, HtmlEscaper.Option... options) Applies HTML escaping to the specified character array.static voidescape(char[] charArr, Writer writer, Set<HtmlEscaper.Option> options) Applies HTML escaping to the specified character array and writes the result to the specified writer.static voidescape(char[] charArr, Writer writer, HtmlEscaper.Option... options) Applies HTML escaping to the specified character array and writes the result to the specified writer.static Stringescape(char[] charArr, Set<HtmlEscaper.Option> options) Applies HTML escaping to the specified character array.static Stringescape(char[] charArr, HtmlEscaper.Option... options) Applies HTML escaping to the specified character array.static voidescape(CharSequence charSequence, Writer writer, Set<HtmlEscaper.Option> options) Applies HTML escaping to the specified string and writes the result to the specified writer.static voidescape(CharSequence charSequence, Writer writer, HtmlEscaper.Option... options) Applies HTML escaping to the specified string and writes the result to the specified writer.static Stringescape(CharSequence charSequence, Set<HtmlEscaper.Option> options) Applies HTML escaping to the specified string.static Stringescape(CharSequence charSequence, HtmlEscaper.Option... options) Applies HTML escaping to the specified string.
-
Method Details
-
escape
Applies HTML escaping to the specified string.- Parameters:
charSequence- String to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies HTML escaping to the specified string.- Parameters:
charSequence- String to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
@WillNotClose public static void escape(CharSequence charSequence, Writer writer, HtmlEscaper.Option... options) throws IOException Applies HTML escaping to the specified string and writes the result to the specified writer.- Parameters:
charSequence- String to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(CharSequence charSequence, Writer writer, Set<HtmlEscaper.Option> options) throws IOException Applies HTML escaping to the specified string and writes the result to the specified writer.- Parameters:
charSequence- String to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
Applies HTML escaping to the specified character array.- Parameters:
charArr- Character array to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies HTML escaping to the specified character array.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arrayoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies HTML escaping to the specified character array.- Parameters:
charArr- Character array to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
public static String escape(char[] charArr, int offset, int length, Set<HtmlEscaper.Option> options) Applies HTML escaping to the specified character array.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arrayoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
@WillNotClose public static void escape(char[] charArr, Writer writer, HtmlEscaper.Option... options) throws IOException Applies HTML escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(char[] charArr, int offset, int length, Writer writer, HtmlEscaper.Option... options) throws IOException Applies HTML escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arraywriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(char[] charArr, Writer writer, Set<HtmlEscaper.Option> options) throws IOException Applies HTML escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(char[] charArr, int offset, int length, Writer writer, Set<HtmlEscaper.Option> options) throws IOException Applies HTML escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arraywriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-