Class ParseHelper
Note: this is an implementation helper, most methods are not intended for usage outside of this library.
-
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
static final byte
static final byte
Non-fatal unexpected EOFstatic final byte
Generic warning about a property value -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic PseudoCondition
createPseudoElementCondition
(String pseudoElement) Create a single pseudo-element condition, like::first-letter
.static boolean
equalSelectorList
(SelectorList list1, SelectorList list2) static boolean
equalsIgnoreCase
(CharSequence seq, CharSequence lcString) Tests if the two given character sequences are the same, ignoring the case considerations except for the fact that the second argument must be lower case.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 whitespace (0x20) and backslash (x5c).static CharSequence
Escapes characters that have a special meaning for CSS, excluding whitespace (0x20) and backslash (x5c).static String
escapeString
(String text, char quoteChar) static String
escapeString
(String text, char quoteChar, boolean endOfString) static boolean
isTransformFunction
(String functionName) For internal use by the library, may be removed in the future.static boolean
matchAttrType
(String dataType, CSSValueSyntax.Category cat) For internal use by the library, may be removed in the future.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) Escape the given string according to CSS syntax.static String
safeEscape
(String text, boolean escapeSurrogates) Escape the given string according to CSS syntax.static boolean
startsWithIgnoreCase
(CharSequence seq, String lcString) Tests if the givenCharSequence
starts with the specified lower case string, but ignoring the case of the first argument.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 CSS 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:
-
ERR_UNSUPPORTED
public static final byte ERR_UNSUPPORTED- 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:
-
WARN_VALUE
public static final byte WARN_VALUEGeneric warning about a property value- See Also:
-
WARN_UNEXPECTED_EOF
public static final byte WARN_UNEXPECTED_EOFNon-fatal unexpected EOF- 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 string according to CSS syntax.For convenience, if the string contains an escape sequence escaping a private or unassigned character, the corresponding backslash is not escaped.
For additional safety, when hex-escaping a code point it will put a whitespace separator if the next character is an ASCII one, even if that character is not a valid hexadecimal digit.
- Parameters:
text
- the text to escape.- Returns:
- the escaped text.
-
safeEscape
Escape the given string according to CSS syntax.For convenience, if the string contains an escape sequence escaping a private or unassigned character, the corresponding backslash is not escaped.
For additional safety, when hex-escaping a code point it will put a whitespace separator if the next character is an ASCII one, even if that character is not a valid hexadecimal digit.
- 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 whitespace (0x20) and backslash (x5c).Note: this is an implementation helper method, not intended for usage outside of this library. May be removed at any time without previous notice.
- Parameters:
strval
- the sequence to escape.- Returns:
- the escaped string.
-
escapeCssCharsAndFirstChar
Escapes characters that have a special meaning for CSS, excluding whitespace (0x20) and backslash (x5c).If the first character is a number, also escapes it.
Note: this is an implementation helper method, not intended for usage outside of this library. May be removed at any time without previous notice.
- 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 CSS unit associated to the given unit string.- Parameters:
unit
- the unit string (must be interned).- Returns:
- the associated CSS unit, or
CSS_OTHER
if the unit is not known.
-
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
Tests if the givenCharSequence
starts with the specified lower case string, but ignoring the case of the first argument.- Parameters:
seq
- the non-null
sequence to check.lcString
- the non-null
lower case prefix that should be matched.- Returns:
true
if the character sequence represented by the second argument is a prefix of the character sequence in the first argument;
-
equalsIgnoreCase
Tests if the two given character sequences are the same, ignoring the case considerations except for the fact that the second argument must be lower case.- Parameters:
seq
- the non-null
sequence to compare to the second argument.lcString
- the non-null
lower case sequence to compare to the first argument.- Returns:
true
if the two arguments represent an equivalentCharSequence
ignoring case.
-
createPseudoElementCondition
Create a single pseudo-element condition, like::first-letter
.- Parameters:
pseudoElement
- the pseudo-element.- Returns:
- the pseudo-element condition.
-
isTransformFunction
For internal use by the library, may be removed in the future.Determine if the name is a transform function.
- Parameters:
functionName
- the function name.- Returns:
- true if the name is a transform function.
-
matchAttrType
For internal use by the library, may be removed in the future.- Parameters:
dataType
- the attr data type.cat
- the grammar data type category to check.- Returns:
- true if the data type matches the syntax category.
-