diff options
author | Jack Moffitt <jack@metajack.im> | 2014-08-28 09:34:23 -0600 |
---|---|---|
committer | Jack Moffitt <jack@metajack.im> | 2014-09-08 20:21:42 -0600 |
commit | c6ab60dbfc6da7b4f800c9e40893c8b58413960c (patch) | |
tree | d1d74076cf7fa20e4f77ec7cb82cae98b67362cb /components/util/namespace.rs | |
parent | db2f642c32fc5bed445bb6f2e45b0f6f0b4342cf (diff) | |
download | servo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.tar.gz servo-c6ab60dbfc6da7b4f800c9e40893c8b58413960c.zip |
Cargoify servo
Diffstat (limited to 'components/util/namespace.rs')
-rw-r--r-- | components/util/namespace.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/components/util/namespace.rs b/components/util/namespace.rs new file mode 100644 index 00000000000..1f32ae83017 --- /dev/null +++ b/components/util/namespace.rs @@ -0,0 +1,43 @@ +/* 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/. */ + +#[deriving(PartialEq, Clone, Encodable)] +pub enum Namespace { + Null, + HTML, + XML, + XMLNS, + XLink, + SVG, + MathML, + Other(String) +} + +impl Namespace { + /// Empty string for "no namespace" + pub fn from_str(url: &str) -> Namespace { + match 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_string()) + } + } + pub fn to_str<'a>(&'a self) -> &'a str { + match *self { + Null => "", + HTML => "http://www.w3.org/1999/xhtml", + XML => "http://www.w3.org/XML/1998/namespace", + XMLNS => "http://www.w3.org/2000/xmlns/", + XLink => "http://www.w3.org/1999/xlink", + SVG => "http://www.w3.org/2000/svg", + MathML => "http://www.w3.org/1998/Math/MathML", + Other(ref x) => x.as_slice() + } + } +} |