From 43d527fcc84efd76a42dd85a7cb6331f391ad005 Mon Sep 17 00:00:00 2001 From: zakorgyula Date: Tue, 16 Feb 2016 08:01:39 +0100 Subject: Move parse_integer and parse_unsigned_integer from util::str to style::attr --- components/script/dom/htmltableelement.rs | 7 +++-- components/style/attr.rs | 47 +++++++++++++++++++++++++++++-- components/util/str.rs | 44 ----------------------------- 3 files changed, 49 insertions(+), 49 deletions(-) (limited to 'components') diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index c2a2e31d2b7..94c0b6dc986 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -18,7 +18,8 @@ use dom::node::{Node, document_from_node}; use dom::virtualmethods::VirtualMethods; use std::cell::Cell; use string_cache::Atom; -use util::str::{self, DOMString, LengthOrPercentageOrAuto}; +use style::attr::parse_unsigned_integer; +use util::str::{DOMString, LengthOrPercentageOrAuto}; #[dom_struct] pub struct HTMLTableElement { @@ -176,12 +177,12 @@ impl VirtualMethods for HTMLTableElement { atom!("border") => { // According to HTML5 ยง 14.3.9, invalid values map to 1px. self.border.set(mutation.new_value(attr).map(|value| { - str::parse_unsigned_integer(value.chars()).unwrap_or(1) + parse_unsigned_integer(value.chars()).unwrap_or(1) })); } atom!("cellspacing") => { self.cellspacing.set(mutation.new_value(attr).and_then(|value| { - str::parse_unsigned_integer(value.chars()) + parse_unsigned_integer(value.chars()) })); }, _ => {}, diff --git a/components/style/attr.rs b/components/style/attr.rs index 31b91319ddd..7c85975ee83 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -5,12 +5,13 @@ use app_units::Au; use cssparser::{self, Color, RGBA}; use euclid::num::Zero; +use num::ToPrimitive; use std::ascii::AsciiExt; use std::ops::Deref; use string_cache::{Atom, Namespace}; use url::Url; -use util::str::{DOMString, LengthOrPercentageOrAuto, WHITESPACE, parse_unsigned_integer, parse_length}; -use util::str::{split_html_space_chars, str_join, parse_integer}; +use util::str::{DOMString, LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS, WHITESPACE}; +use util::str::{parse_length, read_numbers, split_html_space_chars, str_join}; use values::specified::{Length}; // Duplicated from script::dom::values. @@ -29,6 +30,48 @@ pub enum AttrValue { Url(DOMString, Option), } +/// Shared implementation to parse an integer according to +/// or +/// +fn do_parse_integer>(input: T) -> Option { + let mut input = input.skip_while(|c| { + HTML_SPACE_CHARACTERS.iter().any(|s| s == c) + }).peekable(); + + let sign = match input.peek() { + None => return None, + Some(&'-') => { + input.next(); + -1 + }, + Some(&'+') => { + input.next(); + 1 + }, + Some(_) => 1, + }; + + let value = read_numbers(input); + + value.and_then(|value| value.checked_mul(sign)) +} + +/// Parse an integer according to +/// . +pub fn parse_integer>(input: T) -> Option { + do_parse_integer(input).and_then(|result| { + result.to_i32() + }) +} + +/// Parse an integer according to +/// +pub fn parse_unsigned_integer>(input: T) -> Option { + do_parse_integer(input).and_then(|result| { + result.to_u32() + }) +} + impl AttrValue { pub fn from_serialized_tokenlist(tokens: DOMString) -> AttrValue { let atoms = diff --git a/components/util/str.rs b/components/util/str.rs index 6a06b624d14..2ffde43fedf 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -4,7 +4,6 @@ use app_units::Au; use libc::c_char; -use num_lib::ToPrimitive; use std::borrow::ToOwned; use std::convert::AsRef; use std::ffi::CStr; @@ -174,49 +173,6 @@ pub fn read_numbers>(mut iter: Peekable) -> Option or -/// -fn do_parse_integer>(input: T) -> Option { - let mut input = input.skip_while(|c| { - HTML_SPACE_CHARACTERS.iter().any(|s| s == c) - }).peekable(); - - let sign = match input.peek() { - None => return None, - Some(&'-') => { - input.next(); - -1 - }, - Some(&'+') => { - input.next(); - 1 - }, - Some(_) => 1, - }; - - let value = read_numbers(input); - - value.and_then(|value| value.checked_mul(sign)) -} - -/// Parse an integer according to -/// . -pub fn parse_integer>(input: T) -> Option { - do_parse_integer(input).and_then(|result| { - result.to_i32() - }) -} - -/// Parse an integer according to -/// -pub fn parse_unsigned_integer>(input: T) -> Option { - do_parse_integer(input).and_then(|result| { - result.to_u32() - }) -} - #[derive(Clone, Copy, Debug, HeapSizeOf, PartialEq)] pub enum LengthOrPercentageOrAuto { Auto, -- cgit v1.2.3