Class CSSNumberHelper

java.lang.Object
com.helger.css.utils.CSSNumberHelper

@Immutable public final class CSSNumberHelper extends Object
Provides number handling sanity methods.
Author:
Philip Helger
  • Method Details

    • getMatchingUnitInclPercentage

      @Nullable public static ECSSUnit getMatchingUnitInclPercentage(@Nonnull String sCSSValue)
      Try to find the unit that is used in the specified values. This check is done using "endsWith" so you have to make sure, that no trailing spaces are contained in the passed value. This check includes a check for percentage values (e.g. 10%)
      Parameters:
      sCSSValue - The value to check. May not be null.
      Returns:
      null if no matching unit from ECSSUnit was found.
      See Also:
    • getMatchingUnitExclPercentage

      @Nullable public static ECSSUnit getMatchingUnitExclPercentage(@Nonnull String sCSSValue)
      Try to find the unit that is used in the specified values. This check is done using "endsWith" so you have to make sure, that no trailing spaces are contained in the passed value. This check excludes a check for percentage values (e.g. 10%)
      Parameters:
      sCSSValue - The value to check. May not be null.
      Returns:
      null if no matching unit from ECSSUnit was found.
      See Also:
    • isNumberValue

      public static boolean isNumberValue(@Nullable String sCSSValue)
      Check if the passed value is a pure numeric value without a unit.
      Parameters:
      sCSSValue - The value to be checked. May be null and is automatically trimmed inside.
      Returns:
      true if the passed value is a pure decimal numeric value after trimming, false otherwise.
    • isValueWithUnit

      public static boolean isValueWithUnit(@Nullable String sCSSValue)
      Check if the passed string value consists of a numeric value and a unit as in 5px. This method includes the percentage unit.
      Parameters:
      sCSSValue - The value to be parsed. May be null and is trimmed inside this method.
      Returns:
      true if the passed value consist of a number and a unit, false otherwise.
      See Also:
    • isValueWithUnit

      public static boolean isValueWithUnit(@Nullable String sCSSValue, boolean bWithPerc)
      Check if the passed string value consists of a numeric value and a unit as in 5px.
      Parameters:
      sCSSValue - The value to be parsed. May be null and is trimmed inside this method.
      bWithPerc - true to include the percentage unit, false to exclude the percentage unit.
      Returns:
      true if the passed value consist of a number and a unit, false otherwise.
      See Also:
    • getValueWithUnit

      @Nullable public static CSSSimpleValueWithUnit getValueWithUnit(@Nullable String sCSSValue)
      Convert the passed string value with unit into a structured CSSSimpleValueWithUnit. Example: parsing 5px will result in the numeric value 5 and the unit ECSSUnit.PX. The special value "0" is returned with the unit "px". This method includes the percentage unit.
      Parameters:
      sCSSValue - The value to be parsed. May be null and is trimmed inside this method.
      Returns:
      null if the passed value could not be converted to value and unit.
    • getValueWithUnit

      @Nullable public static CSSSimpleValueWithUnit getValueWithUnit(@Nullable String sCSSValue, boolean bWithPerc)
      Convert the passed string value with unit into a structured CSSSimpleValueWithUnit. Example: parsing 5px will result in the numeric value 5 and the unit ECSSUnit.PX. The special value "0" is returned with the unit "px".
      Parameters:
      sCSSValue - The value to be parsed. May be null and is trimmed inside this method.
      bWithPerc - true to include the percentage unit, false to exclude the percentage unit.
      Returns:
      null if the passed value could not be converted to value and unit.