Class ParseHelper

java.lang.Object
io.sf.carte.doc.style.css.parser.ParseHelper

public class ParseHelper extends Object
Methods that are useful for CSS parsing.
  • Field Details

  • Constructor Details

    • ParseHelper

      public ParseHelper()
  • Method Details

    • unescapeStringValue

      public static String unescapeStringValue(String value)
    • 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 - if false, control characters are not unescaped.
      replaceNull - if false, 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 and replaceNull is false.
    • escape

      public static String escape(String text)
      Escape a string according to CSS syntax, preserving escaped hex characters and surrogates.
      Parameters:
      text - the text to escape.
      Returns:
      the escaped string.
    • escape

      public static String escape(String text, boolean preserveHexEscapes, boolean escapeSurrogates)
      Escape a string according to CSS syntax.
      Parameters:
      text - the text to escape.
      preserveHexEscapes - if true, escaped hex characters shall be preserved (instead of escaping its backslash).
      escapeSurrogates - if true, surrogate characters shall be escaped, otherwise preserved.
      Returns:
      the escaped string.
    • safeEscape

      public 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.
      Parameters:
      text - the text to escape.
      escapeSurrogates - true if surrogates have to be escaped.
      Returns:
      the escaped text.
    • escapeString

      public static String escapeString(String text, char quoteChar)
    • escapeString

      public static String escapeString(String text, char quoteChar, boolean endOfString)
    • quote

      public static String quote(String text, char quote)
      Quote a string according to the supplied quote character.
      Parameters:
      text - the string to quote.
      quote - the character to be used as quote.
      Returns:
      the quoted string.
    • escapeCssChars

      public static CharSequence escapeCssChars(CharSequence strval)
      Escapes characters that have a special meaning for CSS, excluding backslash (x5c).
      Parameters:
      strval - the sequence to escape.
      Returns:
      the escaped string.
    • escapeCssCharsAndFirstChar

      public static CharSequence escapeCssCharsAndFirstChar(CharSequence strval)
      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

      public static CharSequence escapeAllBackslash(CharSequence strval)
      Escapes all the backslash characters found in the given string.
      Parameters:
      strval - the string to be escaped.
      Returns:
      the escaped string.
    • escapeBackslash

      public static CharSequence escapeBackslash(CharSequence strval)
      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

      public static String escapeControl(CharSequence strval)
      Escapes control characters.
      Parameters:
      strval - the string to escape.
      Returns:
      the escaped string.
    • unitFromString

      public static short unitFromString(String unit)
      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

      public static String parseIdent(String ident) throws DOMException
      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

      public static boolean equalSelectorList(SelectorList list1, SelectorList list2)
    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(CharSequence seq, String lcString)
    • equalsIgnoreCase

      public static boolean equalsIgnoreCase(CharSequence seq, String lcString)