diff options
Diffstat (limited to 'components/util')
-rw-r--r-- | components/util/lib.rs | 1 | ||||
-rw-r--r-- | components/util/str.rs | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/components/util/lib.rs b/components/util/lib.rs index 46e8b0b60df..3f4146eedfe 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -26,6 +26,7 @@ extern crate sync; extern crate task_info; extern crate "time" as std_time; extern crate string_cache; +extern crate unicode; extern crate url; #[phase(plugin)] diff --git a/components/util/str.rs b/components/util/str.rs index 6e88f0ba4f8..f08ae1178d9 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -7,6 +7,7 @@ use geometry::Au; use std::from_str::FromStr; use std::iter::Filter; use std::str::{CharEq, CharSplits}; +use unicode::char::to_lowercase; pub type DOMString = String; pub type StaticCharVec = &'static [char]; @@ -184,3 +185,22 @@ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto { } +#[deriving(Clone, Eq, PartialEq, Hash, Show)] +pub struct LowercaseString { + inner: String, +} + +impl LowercaseString { + pub fn new(s: &str) -> LowercaseString { + LowercaseString { + inner: s.chars().map(to_lowercase).collect(), + } + } +} + +impl Str for LowercaseString { + #[inline] + fn as_slice(&self) -> &str { + self.inner.as_slice() + } +} |