Class CSSParseHelper

java.lang.Object
com.helger.css.parser.CSSParseHelper

@Immutable public final class CSSParseHelper extends Object
This class is used by the generated parsers to do some common stuff.
Author:
Philip Helger
  • Field Details

    • URL_ESCAPE_CHAR

      public static final char URL_ESCAPE_CHAR
      The character used to quote elements in CSS URLs
      See Also:
  • Method Details

    • extractStringValue

      @Nullable public static String extractStringValue(@Nullable String sStr)
      Remove surrounding quotes (single or double) of a string (if present). If the start and the end quote are not equal, nothing happens.
      Parameters:
      sStr - The string where the quotes should be removed
      Returns:
      The string without quotes.
    • unescapeURL

      @Nonnull public static String unescapeURL(@Nonnull String sEscapedURL)
      Unescape all escaped characters in a CSS URL. All characters masked with a '\\' character replaced.
      Parameters:
      sEscapedURL - The escaped URL. May not be null!
      Returns:
      The unescaped URL or the original string, if not a single escape sequence is found.
    • trimUrl

      @Nonnull public static String trimUrl(@Nonnull CharSequence s)
      Remove the leading "url(" and the trailing ")" from an URL CSS value. No check is performed for the existence of a leading "url("! This method should only be called from within the parser.
      Parameters:
      s - The value to remove the string from.
      Returns:
      The trimmed value. Never null.
    • splitNumber

      @Nonnull public static String splitNumber(@Nonnull StringBuilder aPattern)
    • validateIdentifier

      @Nonnull public static String validateIdentifier(@Nonnull StringBuilder aPattern)
      In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".
      CSS Variables on the other hand allow for double dashes: https://www.w3.org/TR/css-variables-1/#defining-variables
      Source: http://stackoverflow.com/questions/30819462/can-css-identifiers-begin-with- two-hyphens
      Parameters:
      aPattern - pattern to check
      Returns:
      The input string
    • unescapeUnicode

      @Nonnull public static String unescapeUnicode(StringBuilder aImage)
      Unescape e.g. \26 or \000026 to &.
      Parameters:
      aImage - Source string
      Returns:
      Unmasked string
    • unescapeOther

      @Nonnull public static String unescapeOther(StringBuilder aImage)
      Unescape e.g. \x to x.
      Parameters:
      aImage - Source string
      Returns:
      Unmasked string