Class CssEscape
- Object
-
- org.unbescape.css.CssEscape
-
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:
- Level, which defines how deep the escape operation must be (what
chars are to be considered eligible for escaping, depending on the specific
needs of the scenario). Its values are defined by the
CssIdentifierEscapeLevel
andCssStringEscapeLevel
enums. - Type, which defines whether escaping should be performed by means of backslash escapes
or by means of hexadecimal numerical escape sequences.
Its values are defined by the
CssIdentifierEscapeType
andCssStringEscapeType
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:
- Complete set of CSS Backslash Escapes supported (e.g. \+, \(, \), etc.).
- Full set of escape syntax rules supported, both for CSS identifiers and CSS Strings (or literals).
- Non-standard tweaks supported: \: not used because of lacking support in Internet Explorer < 8, \_ escaped at the beginning of identifiers for better Internet Explorer 6 support, etc.
- Hexadecimal escapes (a.k.a. unicode escapes) are supported both in escape and unescape operations, and both in compact (\E1 ) and six-digit forms (\0000E1).
- Support for the whole Unicode character set: \u0000 to \u10FFFF, including characters not representable by only one char in Java (>\uFFFF).
- Support for unescaping unicode characters > U+FFFF both when represented in standard form (one char, \20000) and non-standard (surrogate pair, \D840\DC00, used by older WebKit browsers).
There are four different input/output modes that can be used in escape/unescape operations:
- String input, String output: Input is specified as a String object and output is returned as another. In order to improve memory performance, all escape and unescape operations will return the exact same input object as output if no escape/unescape modifications are required.
- String input, java.io.Writer output: Input will be read from a String and output will be written into the specified java.io.Writer.
- java.io.Reader input, java.io.Writer output: Input will be read from a Reader and output will be written into the specified java.io.Writer.
- char[] input, java.io.Writer output: Input will be read from a char array (char[]) and output will be written into the specified java.io.Writer. Two int arguments called offset and len will be used for specifying the part of the char[] that should be escaped/unescaped. These methods should be called with offset = 0 and len = text.length in order to process the whole char[].
- Backslash escapes
- Escape sequences performed by means of prefixing a backslash (\) to the escaped char: \+, \(, \)
- HEXA escapes
- Complete representation of unicode codepoints up to U+10FFFF, in two forms:
- Compact: non-zero-padded hexadecimal representation (\E1 ), followed by an optional whitespace (U+0020), required if after the escaped character comes a hexadecimal digit ([0-9A-Fa-f]) or another whitespace ( ).
- Six-digit: zero-padded hexadecimal representation (\0000E1), followed by an optional whitespace (U+0020), required if after the escaped character comes another whitespace ( ).
- Unicode Codepoint
- Each of the int values conforming the Unicode code space. Normally corresponding to a Java char primitive value (codepoint <= \uFFFF), but might be two chars for codepoints \u10000 to \u10FFFF if the first char is a high surrogate (\uD800 to \uDBFF) and the second is a low surrogate (\uDC00 to \uDFFF).
The following references apply:
- Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification [w3.org]
- CSS character escape sequences [mathiasbynens.be]
- CSS escapes tester [mothereff.in]
- Since:
- 1.0.0
- Author:
- Daniel Fernández
- Level, which defines how deep the escape operation must be (what
chars are to be considered eligible for escaping, depending on the specific
needs of the scenario). Its values are defined by the
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
escapeCssIdentifier(char[] text, int offset, int len, java.io.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, java.io.Writer writer, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level)
Perform a (configurable) CSS Identifier escape operation on a char[] input.static void
escapeCssIdentifier(java.io.Reader reader, java.io.Writer writer)
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.static void
escapeCssIdentifier(java.io.Reader reader, java.io.Writer writer, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level)
Perform a (configurable) CSS Identifier escape operation on a Reader input, writing the results to a Writer.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 void
escapeCssIdentifier(String text, java.io.Writer writer)
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation on a String input, writing results to a Writer.static void
escapeCssIdentifier(String text, java.io.Writer writer, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level)
Perform a (configurable) CSS Identifier escape operation on a String input, writing the results to a Writer.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, java.io.Writer writer)
Perform a CSS Identifier level 1 (only basic set) escape operation on a char[] input.static void
escapeCssIdentifierMinimal(java.io.Reader reader, java.io.Writer writer)
Perform a CSS Identifier level 1 (only basic set) escape operation on a Reader input, writing results to a Writer.static String
escapeCssIdentifierMinimal(String text)
Perform a CSS Identifier level 1 (only basic set) escape operation on a String input.static void
escapeCssIdentifierMinimal(String text, java.io.Writer writer)
Perform a CSS Identifier level 1 (only basic set) escape operation on a String input, writing results to a Writer.static void
escapeCssString(char[] text, int offset, int len, java.io.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, java.io.Writer writer, CssStringEscapeType type, CssStringEscapeLevel level)
Perform a (configurable) CSS String escape operation on a char[] input.static void
escapeCssString(java.io.Reader reader, java.io.Writer writer)
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.static void
escapeCssString(java.io.Reader reader, java.io.Writer writer, CssStringEscapeType type, CssStringEscapeLevel level)
Perform a (configurable) CSS String escape operation on a Reader input, writing results to a Writer.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 void
escapeCssString(String text, java.io.Writer writer)
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation on a String input, writing results to a Writer.static void
escapeCssString(String text, java.io.Writer writer, CssStringEscapeType type, CssStringEscapeLevel level)
Perform a (configurable) CSS String escape operation on a String input, writing results to a Writer.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, java.io.Writer writer)
Perform a CSS String level 1 (only basic set) escape operation on a char[] input.static void
escapeCssStringMinimal(java.io.Reader reader, java.io.Writer writer)
Perform a CSS String level 1 (only basic set) escape operation on a Reader input, writing results to a Writer.static String
escapeCssStringMinimal(String text)
Perform a CSS String level 1 (only basic set) escape operation on a String input.static void
escapeCssStringMinimal(String text, java.io.Writer writer)
Perform a CSS String level 1 (only basic set) escape operation on a String input, writing results to a Writer.static void
unescapeCss(char[] text, int offset, int len, java.io.Writer writer)
Perform a CSS unescape operation on a char[] input.static void
unescapeCss(java.io.Reader reader, java.io.Writer writer)
Perform a CSS unescape operation on a String input, writing results to a Writer.static String
unescapeCss(String text)
Perform a CSS unescape operation on a String input.static void
unescapeCss(String text, java.io.Writer writer)
Perform a CSS unescape operation on a String input, writing results to a Writer.
-
-
-
Method Detail
-
escapeCssStringMinimal
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:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeCssString
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:
- The CSS String basic escape set:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- The CSS String basic escape set:
-
escapeCssString
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
andCssStringEscapeLevel
argument values.All other String-based escapeCssString*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeCssStringEscapeType
.level
- the escape level to be applied, seeCssStringEscapeLevel
.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeCssStringMinimal
public static void escapeCssStringMinimal(String text, java.io.Writer writer) throws java.io.IOException
Perform a CSS String level 1 (only basic set) escape operation on a String input, writing results to a Writer.
Level 1 means this method will only escape the CSS String basic escape set:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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, Writer, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssString
public static void escapeCssString(String text, java.io.Writer writer) throws java.io.IOException
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation on a String input, writing results to a Writer.
Level 2 means this method will escape:
- The CSS String basic escape set:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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, Writer, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- The CSS String basic escape set:
-
escapeCssString
public static void escapeCssString(String text, java.io.Writer writer, CssStringEscapeType type, CssStringEscapeLevel level) throws java.io.IOException
Perform a (configurable) CSS String escape operation on a String input, writing results to a Writer.
This method will perform an escape operation according to the specified
CssStringEscapeType
andCssStringEscapeLevel
argument values.All other String/Writer-based escapeCssString*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to 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 input is null.type
- the type of escape operation to be performed, seeCssStringEscapeType
.level
- the escape level to be applied, seeCssStringEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssStringMinimal
public static void escapeCssStringMinimal(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform a CSS String level 1 (only basic set) escape operation on a Reader input, writing results to a Writer.
Level 1 means this method will only escape the CSS String basic escape set:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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(Reader, Writer, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssString
public static void escapeCssString(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform a CSS String level 2 (basic set and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.
Level 2 means this method will escape:
- The CSS String basic escape set:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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(Reader, Writer, CssStringEscapeType, CssStringEscapeLevel)
with the following preconfigured values:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- The CSS String basic escape set:
-
escapeCssString
public static void escapeCssString(java.io.Reader reader, java.io.Writer writer, CssStringEscapeType type, CssStringEscapeLevel level) throws java.io.IOException
Perform a (configurable) CSS String escape operation on a Reader input, writing results to a Writer.
This method will perform an escape operation according to the specified
CssStringEscapeType
andCssStringEscapeLevel
argument values.All other Reader/Writer-based escapeCssString*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to 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 input is null.type
- the type of escape operation to be performed, seeCssStringEscapeType
.level
- the escape level to be applied, seeCssStringEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssStringMinimal
public static void escapeCssStringMinimal(char[] text, int offset, int len, java.io.Writer writer) throws java.io.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:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
escapeCssString
public static void escapeCssString(char[] text, int offset, int len, java.io.Writer writer) throws java.io.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:
- The CSS String basic escape set:
- The Backslash Escapes: \" (U+0022) and \' (U+0027).
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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:- type:
CssStringEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssStringEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
- The CSS String basic escape set:
-
escapeCssString
public static void escapeCssString(char[] text, int offset, int len, java.io.Writer writer, CssStringEscapeType type, CssStringEscapeLevel level) throws java.io.IOException
Perform a (configurable) CSS String escape operation on a char[] input.
This method will perform an escape operation according to the specified
CssStringEscapeType
andCssStringEscapeLevel
argument values.All other char[]-based escapeCssString*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
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 input is null.type
- the type of escape operation to be performed, seeCssStringEscapeType
.level
- the escape level to be applied, seeCssStringEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs
-
escapeCssIdentifierMinimal
public 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:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeCssIdentifier
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:
- The CSS Identifier basic escape set:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to be escaped.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
- The CSS Identifier basic escape set:
-
escapeCssIdentifier
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
andCssIdentifierEscapeLevel
argument values.All other String-based escapeCssIdentifier*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to be escaped.type
- the type of escape operation to be performed, seeCssIdentifierEscapeType
.level
- the escape level to be applied, seeCssIdentifierEscapeLevel
.- Returns:
- The escaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no escaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
escapeCssIdentifierMinimal
public static void escapeCssIdentifierMinimal(String text, java.io.Writer writer) throws java.io.IOException
Perform a CSS Identifier level 1 (only basic set) escape operation on a String input, writing results to a Writer.
Level 1 means this method will only escape the CSS Identifier basic escape set:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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, Writer, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssIdentifier
public static void escapeCssIdentifier(String text, java.io.Writer writer) throws java.io.IOException
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation on a String input, writing results to a Writer.
Level 2 means this method will escape:
- The CSS Identifier basic escape set:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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, Writer, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
text
- the String to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- The CSS Identifier basic escape set:
-
escapeCssIdentifier
public static void escapeCssIdentifier(String text, java.io.Writer writer, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level) throws java.io.IOException
Perform a (configurable) CSS Identifier escape operation on a String input, writing the results to a Writer.
This method will perform an escape operation according to the specified
CssIdentifierEscapeType
andCssIdentifierEscapeLevel
argument values.All other String/Writer-based escapeCssIdentifier*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
text
- the String to 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 input is null.type
- the type of escape operation to be performed, seeCssIdentifierEscapeType
.level
- the escape level to be applied, seeCssIdentifierEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssIdentifierMinimal
public static void escapeCssIdentifierMinimal(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform a CSS Identifier level 1 (only basic set) escape operation on a Reader input, writing results to a Writer.
Level 1 means this method will only escape the CSS Identifier basic escape set:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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(Reader, Writer, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssIdentifier
public static void escapeCssIdentifier(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform a CSS Identifier level 2 (basic set and all non-ASCII chars) escape operation on a Reader input, writing results to a Writer.
Level 2 means this method will escape:
- The CSS Identifier basic escape set:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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(Reader, Writer, CssIdentifierEscapeType, CssIdentifierEscapeLevel)
with the following preconfigured values:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
- The CSS Identifier basic escape set:
-
escapeCssIdentifier
public static void escapeCssIdentifier(java.io.Reader reader, java.io.Writer writer, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level) throws java.io.IOException
Perform a (configurable) CSS Identifier escape operation on a Reader input, writing the results to a Writer.
This method will perform an escape operation according to the specified
CssIdentifierEscapeType
andCssIdentifierEscapeLevel
argument values.All other Reader/Writer-based escapeCssIdentifier*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
reader
- the Reader reading the text to 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 input is null.type
- the type of escape operation to be performed, seeCssIdentifierEscapeType
.level
- the escape level to be applied, seeCssIdentifierEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs- Since:
- 1.1.2
-
escapeCssIdentifierMinimal
public static void escapeCssIdentifierMinimal(char[] text, int offset, int len, java.io.Writer writer) throws java.io.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:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
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:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_1_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
escapeCssIdentifier
public static void escapeCssIdentifier(char[] text, int offset, int len, java.io.Writer writer) throws java.io.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:
- The CSS Identifier basic escape set:
- The Backslash Escapes: \ (U+0020), \! (U+0021), \" (U+0022), \# (U+0023), \$ (U+0024), \% (U+0025), \& (U+0026), \' (U+0027), \( (U+0028), \) (U+0029), \* (U+002A), \+ (U+002B), \, (U+002C), \. (U+002E), \/ (U+002F), \; (U+003B), \< (U+003C), \= (U+003D), \> (U+003E), \? (U+003F), \@ (U+0040), \[ (U+005B), \\ (U+005C), \] (U+005D), \^ (U+005E), \` (U+0060), \{ (U+007B), \| (U+007C), \} (U+007D) and \~ (U+007E). Note that the \- (U+002D) escape sequence exists, but will only be used when an identifier starts with two hypens or hyphen + digit. Also, the \_ (U+005F) escape will only be used at the beginning of an identifier to avoid problems with Internet Explorer 6. In the same sense, note that the \: (U+003A) escape sequence is also defined in the standard, but will not be used for escaping as Internet Explorer < 8 does not recognize it.
- Two ranges of non-displayable, control characters: U+0000 to U+001F and U+007F to U+009F.
- All non ASCII characters.
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:- type:
CssIdentifierEscapeType.BACKSLASH_ESCAPES_DEFAULT_TO_COMPACT_HEXA
- level:
CssIdentifierEscapeLevel.LEVEL_2_ALL_NON_ASCII_PLUS_BASIC_ESCAPE_SET
This method is thread-safe.
- Parameters:
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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
- The CSS Identifier basic escape set:
-
escapeCssIdentifier
public static void escapeCssIdentifier(char[] text, int offset, int len, java.io.Writer writer, CssIdentifierEscapeType type, CssIdentifierEscapeLevel level) throws java.io.IOException
Perform a (configurable) CSS Identifier escape operation on a char[] input.
This method will perform an escape operation according to the specified
CssIdentifierEscapeType
andCssIdentifierEscapeLevel
argument values.All other char[]-based escapeCssIdentifier*(...) methods call this one with preconfigured type and level values.
This method is thread-safe.
- Parameters:
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 input is null.type
- the type of escape operation to be performed, seeCssIdentifierEscapeType
.level
- the escape level to be applied, seeCssIdentifierEscapeLevel
.- Throws:
java.io.IOException
- if an input/output exception occurs
-
unescapeCss
public 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.
- Parameters:
text
- the String to be unescaped.- Returns:
- The unescaped result String. As a memory-performance improvement, will return the exact same object as the text input argument if no unescaping modifications were required (and no additional String objects will be created during processing). Will return null if input is null.
-
unescapeCss
public static void unescapeCss(String text, java.io.Writer writer) throws java.io.IOException
Perform a CSS unescape operation on a String input, writing results to a Writer.
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.
- Parameters:
text
- the String to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
unescapeCss
public static void unescapeCss(java.io.Reader reader, java.io.Writer writer) throws java.io.IOException
Perform a CSS unescape operation on a String input, writing results to a Writer.
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.
- Parameters:
reader
- the Reader reading the text to 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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
unescapeCss
public static void unescapeCss(char[] text, int offset, int len, java.io.Writer writer) throws java.io.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.
- Parameters:
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 input is null.- Throws:
java.io.IOException
- if an input/output exception occurs
-
-