aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/str.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/util/str.rs')
-rw-r--r--components/util/str.rs24
1 files changed, 5 insertions, 19 deletions
diff --git a/components/util/str.rs b/components/util/str.rs
index 80cdd1ae230..bc193002ff1 100644
--- a/components/util/str.rs
+++ b/components/util/str.rs
@@ -35,25 +35,11 @@ pub fn null_str_as_empty_ref<'a>(s: &'a Option<DOMString>) -> &'a str {
}
/// Whitespace as defined by HTML5 § 2.4.1.
-struct Whitespace;
-
-impl CharEq for Whitespace {
- #[inline]
- fn matches(&mut self, ch: char) -> bool {
- match ch {
- ' ' | '\t' | '\x0a' | '\x0c' | '\x0d' => true,
- _ => false,
- }
- }
-
- #[inline]
- fn only_ascii(&self) -> bool {
- true
- }
-}
+// TODO(SimonSapin) Maybe a custom Pattern can be more efficient?
+const WHITESPACE: &'static [char] = &[' ', '\t', '\x0a', '\x0c', '\x0d'];
pub fn is_whitespace(s: &str) -> bool {
- s.chars().all(|c| Whitespace.matches(c))
+ s.chars().all(|c| WHITESPACE.contains(&c))
}
/// A "space character" according to:
@@ -144,7 +130,7 @@ pub enum LengthOrPercentageOrAuto {
/// Parses a length per HTML5 § 2.4.4.4. If unparseable, `Auto` is returned.
pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
- value = value.trim_left_matches(Whitespace);
+ value = value.trim_left_matches(WHITESPACE);
if value.len() == 0 {
return LengthOrPercentageOrAuto::Auto
}
@@ -200,7 +186,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA,()> {
}
// Step 3.
- input = input.trim_left_matches(Whitespace).trim_right_matches(Whitespace);
+ input = input.trim_matches(WHITESPACE);
// Step 4.
if input.eq_ignore_ascii_case("transparent") {