public final class CssEscape extends Object
Utility class for performing CSS escape/unescape operations.
This class supports both escaping of CSS identifiers and CSS Strings (or literals).
Configuration of escape/unescape operationsEscape operations can be (optionally) configured by means of:
CssIdentifierEscapeLevel
and CssStringEscapeLevel
enums.CssIdentifierEscapeType
and CssStringEscapeType
enums.Unescape operations need no configuration parameters. Unescape operations will always perform complete unescape of backslash and hexadecimal escapes, including all required tweaks (i.e. optional whitespace characters) needed for unescaping.
FeaturesSpecific features of the CSS escape/unescape operations performed by means of this class:
There are two different input/output modes that can be used in escape/unescape operations:
The following references apply:
Modifier and Type | Method and Description |
---|---|
static void |
escapeCssIdentifier(char[] text,
int offset,
int len,
Writer writer)
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation
on a char[] input.
|
static void |
escapeCssIdentifier(char[] text,
int offset,
int len,
Writer writer,
CssIdentifierEscapeType type,
CssIdentifierEscapeLevel level)
Perform a (configurable) CSS Identifier escape operation on a char[] input.
|
static String |
escapeCssIdentifier(String text)
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation
on a String input.
|
static String |
escapeCssIdentifier(String text,
CssIdentifierEscapeType type,
CssIdentifierEscapeLevel level)
Perform a (configurable) CSS Identifier escape operation on a String input.
|
static void |
escapeCssIdentifierMinimal(char[] text,
int offset,
int len,
Writer writer)
Perform a CSS Identifier level 1 (only basic set) escape operation
on a char[] input.
|
static String |
escapeCssIdentifierMinimal(String text)
Perform a CSS Identifier level 1 (only basic set) escape operation
on a String input.
|
static void |
escapeCssString(char[] text,
int offset,
int len,
Writer writer)
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation
on a char[] input.
|
static void |
escapeCssString(char[] text,
int offset,
int len,
Writer writer,
CssStringEscapeType type,
CssStringEscapeLevel level)
Perform a (configurable) CSS String escape operation on a char[] input.
|
static String |
escapeCssString(String text)
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation
on a String input.
|
static String |
escapeCssString(String text,
CssStringEscapeType type,
CssStringEscapeLevel level)
Perform a (configurable) CSS String escape operation on a String input.
|
static void |
escapeCssStringMinimal(char[] text,
int offset,
int len,
Writer writer)
Perform a CSS String level 1 (only basic set) escape operation
on a char[] input.
|
static String |
escapeCssStringMinimal(String text)
Perform a CSS String level 1 (only basic set) escape operation
on a String input.
|
static void |
unescapeCss(char[] text,
int offset,
int len,
Writer writer)
Perform a CSS unescape operation on a char[] input.
|
static String |
unescapeCss(String text)
Perform a CSS unescape operation on a String input.
|
public static String escapeCssStringMinimal(String text)
Perform a CSS String level 1 (only basic set) escape operation on a String input.
Level 1 means this method will only escape the CSS String basic escape set:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls escapeCssString(String, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssStringEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the String to be escaped.public static String escapeCssString(String text)
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation on a String input.
Level 2 means this method will escape:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls
escapeCssString(String, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssStringEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the String to be escaped.public static String escapeCssString(String text, CssStringEscapeType type, CssStringEscapeLevel level)
Perform a (configurable) CSS String escape operation on a String input.
This method will perform an escape operation according to the specified
CssStringEscapeType
and
CssStringEscapeLevel
argument values.
All other String-based escapeCssString*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
text
- the String to be escaped.type
- the type of escape operation to be performed, see
CssStringEscapeType
.level
- the escape level to be applied, see CssStringEscapeLevel
.public static void escapeCssStringMinimal(char[] text, int offset, int len, Writer writer) throws IOException
Perform a CSS String level 1 (only basic set) escape operation on a char[] input.
Level 1 means this method will only escape the CSS String basic escape set:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls
escapeCssString(char[], int, int, java.io.Writer, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssStringEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will
be written at all to this writer if text is null.IOException
- if an input/output exception occurspublic static void escapeCssString(char[] text, int offset, int len, Writer writer) throws IOException
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation on a char[] input.
Level 2 means this method will escape:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls
escapeCssString(char[], int, int, java.io.Writer, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssStringEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will
be written at all to this writer if text is null.IOException
- if an input/output exception occurspublic static void escapeCssString(char[] text, int offset, int len, Writer writer, CssStringEscapeType type, CssStringEscapeLevel level) throws IOException
Perform a (configurable) CSS String escape operation on a char[] input.
This method will perform an escape operation according to the specified
CssStringEscapeType
and
CssStringEscapeLevel
argument values.
All other char[]-based escapeCssString*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will
be written at all to this writer if text is null.type
- the type of escape operation to be performed, see
CssStringEscapeType
.level
- the escape level to be applied, see CssStringEscapeLevel
.IOException
- if an input/output exception occurspublic static String escapeCssIdentifierMinimal(String text)
Perform a CSS Identifier level 1 (only basic set) escape operation on a String input.
Level 1 means this method will only escape the CSS Identifier basic escape set:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls escapeCssIdentifier(String, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssIdentifierEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the String to be escaped.public static String escapeCssIdentifier(String text)
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation on a String input.
Level 2 means this method will escape:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls
escapeCssIdentifier(String, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssIdentifierEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the String to be escaped.public static String escapeCssIdentifier(String text, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level)
Perform a (configurable) CSS Identifier escape operation on a String input.
This method will perform an escape operation according to the specified
CssIdentifierEscapeType
and
CssIdentifierEscapeLevel
argument values.
All other String-based escapeCssIdentifier*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
text
- the String to be escaped.type
- the type of escape operation to be performed, see
CssIdentifierEscapeType
.level
- the escape level to be applied, see CssIdentifierEscapeLevel
.public static void escapeCssIdentifierMinimal(char[] text, int offset, int len, Writer writer) throws IOException
Perform a CSS Identifier level 1 (only basic set) escape operation on a char[] input.
Level 1 means this method will only escape the CSS Identifier basic escape set:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls
escapeCssIdentifier(char[], int, int, java.io.Writer, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssIdentifierEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will
be written at all to this writer if text is null.IOException
- if an input/output exception occurspublic static void escapeCssIdentifier(char[] text, int offset, int len, Writer writer) throws IOException
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation on a char[] input.
Level 2 means this method will escape:
This escape will be performed by using Backslash escapes whenever possible. For escaped characters that do not have an associated Backslash, default to \FF Hexadecimal Escapes.
This method calls
escapeCssIdentifier(char[], int, int, java.io.Writer, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
CssIdentifierEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will
be written at all to this writer if text is null.IOException
- if an input/output exception occurspublic static void escapeCssIdentifier(char[] text, int offset, int len, Writer writer, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level) throws IOException
Perform a (configurable) CSS Identifier escape operation on a char[] input.
This method will perform an escape operation according to the specified
CssIdentifierEscapeType
and
CssIdentifierEscapeLevel
argument values.
All other char[]-based escapeCssIdentifier*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
text
- the char[] to be escaped.offset
- the position in text at which the escape operation should start.len
- the number of characters in text that should be escaped.writer
- the java.io.Writer to which the escaped result will be written. Nothing will
be written at all to this writer if text is null.type
- the type of escape operation to be performed, see
CssIdentifierEscapeType
.level
- the escape level to be applied, see CssIdentifierEscapeLevel
.IOException
- if an input/output exception occurspublic static String unescapeCss(String text)
Perform a CSS unescape operation on a String input.
No additional configuration arguments are required. Unescape operations will always perform complete CSS unescape of backslash and hexadecimal escape sequences.
This method is thread-safe.
text
- the String to be unescaped.public static void unescapeCss(char[] text, int offset, int len, Writer writer) throws IOException
Perform a CSS unescape operation on a char[] input.
No additional configuration arguments are required. Unescape operations will always perform complete CSS unescape of backslash and hexadecimal escape sequences.
This method is thread-safe.
text
- the char[] to be unescaped.offset
- the position in text at which the unescape operation should start.len
- the number of characters in text that should be unescaped.writer
- the java.io.Writer to which the unescaped result will be written. Nothing will
be written at all to this writer if text is null.IOException
- if an input/output exception occursCopyright © 2015 The UNBESCAPE team. All rights reserved.