diff options
author | James Graham <james@hoppipolla.co.uk> | 2013-09-10 10:24:40 +0100 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2013-11-12 17:39:04 +0900 |
commit | 15b9d4d19967ed96bd459bf15cae5b793567c227 (patch) | |
tree | 5e1237d9bd62386b327e30e52bf8870f5ff9f107 /src/components/script/dom/namespace.rs | |
parent | 433f19f5a310f71273f03504261568d393e648ea (diff) | |
download | servo-15b9d4d19967ed96bd459bf15cae5b793567c227.tar.gz servo-15b9d4d19967ed96bd459bf15cae5b793567c227.zip |
Initial support for Attr and namespaces.
Diffstat (limited to 'src/components/script/dom/namespace.rs')
-rw-r--r-- | src/components/script/dom/namespace.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/components/script/dom/namespace.rs b/src/components/script/dom/namespace.rs new file mode 100644 index 00000000000..7fe8e68e232 --- /dev/null +++ b/src/components/script/dom/namespace.rs @@ -0,0 +1,44 @@ +/* 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 dom::bindings::utils::{DOMString, null_str_as_empty_ref}; + +#[deriving(Eq, Clone)] +pub enum Namespace { + Null, + HTML, + XML, + XMLNS, + XLink, + SVG, + MathML, + Other(~str) +} + +impl Namespace { + pub fn from_str(url: &DOMString) -> Namespace { + match null_str_as_empty_ref(url) { + &"http://www.w3.org/1999/xhtml" => HTML, + &"http://www.w3.org/XML/1998/namespace" => XML, + &"http://www.w3.org/2000/xmlns/" => XMLNS, + &"http://www.w3.org/1999/xlink" => XLink, + &"http://www.w3.org/2000/svg" => SVG, + &"http://www.w3.org/1998/Math/MathML" => MathML, + &"" => Null, + ns => Other(ns.to_owned()) + } + } + pub fn to_str(&self) -> DOMString { + match *self { + Null => None, + HTML => Some(~"http://www.w3.org/1999/xhtml"), + XML => Some(~"http://www.w3.org/XML/1998/namespace"), + XMLNS => Some(~"http://www.w3.org/2000/xmlns/"), + XLink => Some(~"http://www.w3.org/1999/xlink"), + SVG => Some(~"http://www.w3.org/2000/svg"), + MathML => Some(~"http://www.w3.org/1998/Math/MathML"), + Other(ref x) => Some(x.to_owned()) + } + } +} |