org.unbescape.css
Class CssEscape

Object
  extended by 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 operations

Escape operations can be (optionally) configured by means of:

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.

Features

Specific features of the CSS escape/unescape operations performed by means of this class:

Input/Output

There are two different input/output modes that can be used in escape/unescape operations:

Glossary

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:
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).

References

The following references apply:

Since:
1.0
Author:
Daniel Fernández

Method Summary
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.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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:

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:

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 text 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:

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:

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 text is null.

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 and CssStringEscapeLevel 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, see CssStringEscapeType.
level - the escape level to be applied, see CssStringEscapeLevel.
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 text is null.

escapeCssStringMinimal

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:

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 text is null.
Throws:
IOException

escapeCssString

public 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:

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 text is null.
Throws:
IOException

escapeCssString

public 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.

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 text is null.
type - the type of escape operation to be performed, see CssStringEscapeType.
level - the escape level to be applied, see CssStringEscapeLevel.
Throws:
IOException

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:

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:

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 text 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:

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:

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 text is null.

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 and CssIdentifierEscapeLevel 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, see CssIdentifierEscapeType.
level - the escape level to be applied, see CssIdentifierEscapeLevel.
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 text is null.

escapeCssIdentifierMinimal

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:

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 text is null.
Throws:
IOException

escapeCssIdentifier

public 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:

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 text is null.
Throws:
IOException

escapeCssIdentifier

public 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.

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 text is null.
type - the type of escape operation to be performed, see CssIdentifierEscapeType.
level - the escape level to be applied, see CssIdentifierEscapeLevel.
Throws:
IOException

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 text is null.

unescapeCss

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.

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 text is null.
Throws:
IOException


Copyright © 2014 The UNBESCAPE team. All rights reserved.