aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/namespace.rs
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-09-23 22:22:45 +0200
committerMs2ger <ms2ger@gmail.com>2014-09-23 22:22:45 +0200
commitd3d7c1dabd8b3a0915b6de22780f834b660a3122 (patch)
tree84db57b876dc879c02dd783edcbc21e7be683771 /components/util/namespace.rs
parent4546d5d23caa3f459b75e9a0bf9e91a3376dc197 (diff)
downloadservo-d3d7c1dabd8b3a0915b6de22780f834b660a3122.tar.gz
servo-d3d7c1dabd8b3a0915b6de22780f834b660a3122.zip
Handle null strings in Namespace::new.
This also avoids a string copy in the rare case of an unrecognized namespace.
Diffstat (limited to 'components/util/namespace.rs')
-rw-r--r--components/util/namespace.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/components/util/namespace.rs b/components/util/namespace.rs
index b33012a9ef1..3dbb298a074 100644
--- a/components/util/namespace.rs
+++ b/components/util/namespace.rs
@@ -2,6 +2,8 @@
* 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 str::DOMString;
+
#[deriving(Eq, PartialEq, Clone, Encodable, Hash, Show)]
pub enum Namespace {
Null,
@@ -16,16 +18,17 @@ pub enum Namespace {
impl Namespace {
/// Empty string for "no namespace"
- pub fn from_str(url: &str) -> Namespace {
+ pub fn from_str(url: Option<DOMString>) -> 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())
+ None => Null,
+ Some(ref ns) if ns.as_slice() == "" => Null,
+ Some(ref ns) if ns.as_slice() == "http://www.w3.org/1999/xhtml" => HTML,
+ Some(ref ns) if ns.as_slice() == "http://www.w3.org/XML/1998/namespace" => XML,
+ Some(ref ns) if ns.as_slice() == "http://www.w3.org/2000/xmlns/" => XMLNS,
+ Some(ref ns) if ns.as_slice() == "http://www.w3.org/1999/xlink" => XLink,
+ Some(ref ns) if ns.as_slice() == "http://www.w3.org/2000/svg" => SVG,
+ Some(ref ns) if ns.as_slice() == "http://www.w3.org/1998/Math/MathML" => MathML,
+ Some(ns) => Other(ns)
}
}
pub fn to_str<'a>(&'a self) -> &'a str {