aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/str.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/util/str.rs')
-rw-r--r--components/util/str.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/components/util/str.rs b/components/util/str.rs
index 9978464ee0d..f00dd8e3ea7 100644
--- a/components/util/str.rs
+++ b/components/util/str.rs
@@ -4,6 +4,7 @@
use app_units::Au;
use cssparser::{self, Color, RGBA};
+use euclid::num::Zero;
use js::conversions::{FromJSValConvertible, ToJSValConvertible, latin1_to_string};
use js::jsapi::{JSContext, JSString, HandleValue, MutableHandleValue};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_StringHasLatin1Chars};
@@ -372,6 +373,17 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
}
}
+/// HTML5 § 2.4.4.5.
+///
+/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-zero-dimension-values
+pub fn parse_nonzero_length(value: &str) -> LengthOrPercentageOrAuto {
+ match parse_length(value) {
+ LengthOrPercentageOrAuto::Length(x) if x == Au::zero() => LengthOrPercentageOrAuto::Auto,
+ LengthOrPercentageOrAuto::Percentage(0.) => LengthOrPercentageOrAuto::Auto,
+ x => x,
+ }
+}
+
/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-font-size
pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
// Steps 1 & 2 are not relevant