java.lang.Object
io.sf.carte.doc.style.css.parser.ParseHelper
Methods that are useful for CSS parsing.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final byte
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
static final byte
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
equalSelectorList
(SelectorList list1, SelectorList list2) static boolean
equalsIgnoreCase
(CharSequence seq, String lcString) static String
Escape a string according to CSS syntax, preserving escaped hex characters and surrogates.static String
Escape a string according to CSS syntax.static CharSequence
escapeAllBackslash
(CharSequence strval) Escapes all the backslash characters found in the given string.static CharSequence
escapeBackslash
(CharSequence strval) Escapes the backslash characters found in the given string, except those that escape hex-encoded codepoints.static String
escapeControl
(CharSequence strval) Escapes control characters.static CharSequence
escapeCssChars
(CharSequence strval) Escapes characters that have a special meaning for CSS, excluding backslash (x5c).static CharSequence
Escapes characters that have a special meaning for CSS, excluding backslash (x5c).static String
escapeString
(String text, char quoteChar) static String
escapeString
(String text, char quoteChar, boolean endOfString) static boolean
isFunctionUnitType
(short unitType) static String
parseIdent
(String ident) Parse an escaped CSS identifier.static String
Quote a string according to the suppliedquote
character.static String
safeEscape
(String text, boolean escapeSurrogates) Escape the given text, but when escaping the backslashes, only do those that do not escape a private or unassigned character.static boolean
startsWithIgnoreCase
(CharSequence seq, String lcString) static String
unescapeStringValue
(String value) static String
unescapeStringValue
(String value, boolean unescapeControl, boolean replaceNull) Changes ISO 10646 escaped character values to the actual characters, when appropriate.static short
unitFromString
(String unit) Retrieves the SAC unit associated to the given unit string.
-
Field Details
-
ERR_UNEXPECTED_CHAR
public static final byte ERR_UNEXPECTED_CHAR- See Also:
-
ERR_WRONG_VALUE
public static final byte ERR_WRONG_VALUE- See Also:
-
ERR_UNMATCHED_PARENTHESIS
public static final byte ERR_UNMATCHED_PARENTHESIS- See Also:
-
ERR_INVALID_IDENTIFIER
public static final byte ERR_INVALID_IDENTIFIER- See Also:
-
ERR_UNEXPECTED_TOKEN
public static final byte ERR_UNEXPECTED_TOKEN- See Also:
-
ERR_UNKNOWN_NAMESPACE
public static final byte ERR_UNKNOWN_NAMESPACE- See Also:
-
ERR_EXPR_SYNTAX
public static final byte ERR_EXPR_SYNTAX- See Also:
-
ERR_RULE_SYNTAX
public static final byte ERR_RULE_SYNTAX- See Also:
-
ERR_UNEXPECTED_EOF
public static final byte ERR_UNEXPECTED_EOF- See Also:
-
WARN_DUPLICATE_SELECTOR
public static final byte WARN_DUPLICATE_SELECTOR- See Also:
-
WARN_IDENT_COMPAT
public static final byte WARN_IDENT_COMPAT- See Also:
-
WARN_PROGID_HACK
public static final byte WARN_PROGID_HACK- See Also:
-
WARN_PROPERTY_NAME
public static final byte WARN_PROPERTY_NAME- See Also:
-
-
Constructor Details
-
ParseHelper
public ParseHelper()
-
-
Method Details
-
unescapeStringValue
-
unescapeStringValue
public static String unescapeStringValue(String value, boolean unescapeControl, boolean replaceNull) throws DOMNullCharacterException Changes ISO 10646 escaped character values to the actual characters, when appropriate.- Parameters:
value
- the string value to unescape.unescapeControl
- iffalse
, control characters are not unescaped.replaceNull
- iffalse
, if NULL is found at the end of a string, it will trigger an exception instead of being replaced by the replacement character.- Returns:
- the unescaped string.
- Throws:
DOMNullCharacterException
- if a null-character browser hack was found andreplaceNull
isfalse
.
-
escape
Escape a string according to CSS syntax, preserving escaped hex characters and surrogates.- Parameters:
text
- the text to escape.- Returns:
- the escaped string.
-
escape
Escape a string according to CSS syntax.- Parameters:
text
- the text to escape.preserveHexEscapes
- iftrue
, escaped hex characters shall be preserved (instead of escaping its backslash).escapeSurrogates
- iftrue
, surrogate characters shall be escaped, otherwise preserved.- Returns:
- the escaped string.
-
safeEscape
Escape the given text, but when escaping the backslashes, only do those that do not escape a private or unassigned character.- Parameters:
text
- the text to escape.escapeSurrogates
-true
if surrogates have to be escaped.- Returns:
- the escaped text.
-
escapeString
-
escapeString
-
quote
Quote a string according to the suppliedquote
character.- Parameters:
text
- the string to quote.quote
- the character to be used as quote.- Returns:
- the quoted string.
-
escapeCssChars
Escapes characters that have a special meaning for CSS, excluding backslash (x5c).- Parameters:
strval
- the sequence to escape.- Returns:
- the escaped string.
-
escapeCssCharsAndFirstChar
Escapes characters that have a special meaning for CSS, excluding backslash (x5c).If the first character is a number, also escapes it.
- Parameters:
strval
- the sequence to escape.- Returns:
- the escaped string.
-
escapeAllBackslash
Escapes all the backslash characters found in the given string.- Parameters:
strval
- the string to be escaped.- Returns:
- the escaped string.
-
escapeBackslash
Escapes the backslash characters found in the given string, except those that escape hex-encoded codepoints.If you have to call it together with
escapeCssCharsAndFirstChar(CharSequence)
, make sure to execute this method first.- Parameters:
strval
- the character sequence to be escaped.- Returns:
- the escaped string.
-
escapeControl
Escapes control characters.- Parameters:
strval
- the string to escape.- Returns:
- the escaped string.
-
unitFromString
Retrieves the SAC unit associated to the given unit string.- Parameters:
unit
- the unit string (must be interned).- Returns:
- the associated SAC unit, or
SAC_DIMENSION
if the unit is not known.
-
isFunctionUnitType
public static boolean isFunctionUnitType(short unitType) -
parseIdent
Parse an escaped CSS identifier.- Parameters:
ident
- the identifier to parse.- Returns:
- the parsed identifier.
- Throws:
DOMException
- DOMException.DOMSTRING_SIZE_ERR if the identifier is the empty string.
DOMException.INVALID_CHARACTER_ERR if the identifier contains invalid characters.
DOMException.SYNTAX_ERR if the identifier does not follow the syntax (e.g. only contains a hyphen-minus, or starts with a hyphen-minus and a digit).
-
equalSelectorList
-
startsWithIgnoreCase
-
equalsIgnoreCase
-