diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2015-01-28 16:29:35 +0100 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2015-01-30 15:07:29 +0100 |
commit | 966af0030a246dfa407d5d17a66020cd331f326d (patch) | |
tree | 43c64db6d1f04dd4f37dc1b4e4d472f712ce8c8f /components/style/namespaces.rs | |
parent | 7359f99f201a359aaebf334a1787d1975c9fa7d4 (diff) | |
download | servo-966af0030a246dfa407d5d17a66020cd331f326d.tar.gz servo-966af0030a246dfa407d5d17a66020cd331f326d.zip |
Upgrade to rust-cssparser master.
* Use associated types
* Avoid mutation to gather parsing results.
Diffstat (limited to 'components/style/namespaces.rs')
-rw-r--r-- | components/style/namespaces.rs | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/components/style/namespaces.rs b/components/style/namespaces.rs deleted file mode 100644 index 53b6467db9c..00000000000 --- a/components/style/namespaces.rs +++ /dev/null @@ -1,49 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use cssparser::Parser; -use std::collections::HashMap; -use string_cache::{Atom, Namespace}; -use parser::ParserContext; - - -#[derive(Clone)] -pub struct NamespaceMap { - pub default: Option<Namespace>, - pub prefix_map: HashMap<String, Namespace>, -} - - -impl NamespaceMap { - pub fn new() -> NamespaceMap { - NamespaceMap { default: None, prefix_map: HashMap::new() } - } -} - - -pub fn parse_namespace_rule(context: &mut ParserContext, input: &mut Parser) - -> Result<(Option<String>, Namespace), ()> { - let prefix = input.try(|input| input.expect_ident()).ok().map(|p| p.into_owned()); - let url = try!(input.expect_url_or_string()); - try!(input.expect_exhausted()); - - let namespace = Namespace(Atom::from_slice(url.as_slice())); - let is_duplicate = match prefix { - Some(ref prefix) => { - context.namespaces.prefix_map.insert(prefix.clone(), namespace.clone()).is_some() - } - None => { - let has_default = context.namespaces.default.is_some(); - if !has_default { - context.namespaces.default = Some(namespace.clone()); - } - has_default - } - }; - if is_duplicate { - Err(()) // "Duplicate @namespace rule" - } else { - Ok((prefix, namespace)) - } -} |