Package com.helger.css.utils
Class CSSNumberHelper
java.lang.Object
com.helger.css.utils.CSSNumberHelper
Provides number handling sanity methods.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic ECSSUnitgetMatchingUnitExclPercentage(String sCSSValue) Try to find the unit that is used in the specified values.static ECSSUnitgetMatchingUnitInclPercentage(String sCSSValue) Try to find the unit that is used in the specified values.static CSSSimpleValueWithUnitgetValueWithUnit(String sCSSValue) Convert the passed string value with unit into a structuredCSSSimpleValueWithUnit.static CSSSimpleValueWithUnitgetValueWithUnit(String sCSSValue, boolean bWithPerc) Convert the passed string value with unit into a structuredCSSSimpleValueWithUnit.static booleanisNumberValue(String sCSSValue) Check if the passed value is a pure numeric value without a unit.static booleanisValueWithUnit(String sCSSValue) Check if the passed string value consists of a numeric value and a unit as in5px.static booleanisValueWithUnit(String sCSSValue, boolean bWithPerc) Check if the passed string value consists of a numeric value and a unit as in5px.
-
Method Details
-
getMatchingUnitInclPercentage
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 benull.- Returns:
nullif no matching unit fromECSSUnitwas found.- See Also:
-
getMatchingUnitExclPercentage
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 benull.- Returns:
nullif no matching unit fromECSSUnitwas found.- See Also:
-
isNumberValue
Check if the passed value is a pure numeric value without a unit.- Parameters:
sCSSValue- The value to be checked. May benulland is automatically trimmed inside.- Returns:
trueif the passed value is a pure decimal numeric value after trimming,falseotherwise.
-
isValueWithUnit
Check if the passed string value consists of a numeric value and a unit as in5px. This method includes the percentage unit.- Parameters:
sCSSValue- The value to be parsed. May benulland is trimmed inside this method.- Returns:
trueif the passed value consist of a number and a unit,falseotherwise.- See Also:
-
isValueWithUnit
Check if the passed string value consists of a numeric value and a unit as in5px.- Parameters:
sCSSValue- The value to be parsed. May benulland is trimmed inside this method.bWithPerc-trueto include the percentage unit,falseto exclude the percentage unit.- Returns:
trueif the passed value consist of a number and a unit,falseotherwise.- See Also:
-
getValueWithUnit
Convert the passed string value with unit into a structuredCSSSimpleValueWithUnit. Example: parsing5pxwill result in the numeric value5and the unitECSSUnit.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 benulland is trimmed inside this method.- Returns:
nullif 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 structuredCSSSimpleValueWithUnit. Example: parsing5pxwill result in the numeric value5and the unitECSSUnit.PX. The special value "0" is returned with the unit "px".- Parameters:
sCSSValue- The value to be parsed. May benulland is trimmed inside this method.bWithPerc-trueto include the percentage unit,falseto exclude the percentage unit.- Returns:
nullif the passed value could not be converted to value and unit.
-