aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/util/str.rs
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-04-05 04:04:34 -0400
committerbors-servo <release+servo@mozilla.com>2014-04-05 04:04:34 -0400
commit2a5f82a76453aebe1ce07f0e0c5b78bead93ed0c (patch)
treed869c9a3f2a65b8f1108c9934bb19cb13b6f1c4a /src/components/util/str.rs
parent0f0b0b33bf7375d834138a3bd3af9ba1921d390d (diff)
parentc451b1c9dc31e91381f10d0cadd1d1377162367f (diff)
downloadservo-2a5f82a76453aebe1ce07f0e0c5b78bead93ed0c.tar.gz
servo-2a5f82a76453aebe1ce07f0e0c5b78bead93ed0c.zip
auto merge of #2032 : brunoabinader/servo/html-whitespace, r=Ms2ger
Specs: http://dom.spec.whatwg.org/#concept-ordered-set-parser http://encoding.spec.whatwg.org/#ascii-whitespace This PR implements the HTMLSpaceCharSplits iterator, used to split a string in a subset of strings separated by valid HTML space characters. Its first usage is upon splitting ```class``` attribute values. Closes #1840.
Diffstat (limited to 'src/components/util/str.rs')
-rw-r--r--src/components/util/str.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/components/util/str.rs b/src/components/util/str.rs
index cdbf1bb9ea9..abd5984b8ef 100644
--- a/src/components/util/str.rs
+++ b/src/components/util/str.rs
@@ -2,7 +2,11 @@
* 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 std::iter::Filter;
+use std::str::CharSplits;
+
pub type DOMString = ~str;
+pub type StaticCharVec = &'static [char];
pub type StaticStringVec = &'static [&'static str];
pub fn null_str_as_empty(s: &Option<DOMString>) -> DOMString {
@@ -31,7 +35,7 @@ pub fn is_whitespace(s: &str) -> bool {
///
/// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#
/// space-character
-pub static HTML_SPACE_CHARACTERS: [char, ..5] = [
+pub static HTML_SPACE_CHARACTERS: StaticCharVec = &[
'\u0020',
'\u0009',
'\u000a',
@@ -39,3 +43,6 @@ pub static HTML_SPACE_CHARACTERS: [char, ..5] = [
'\u000d',
];
+pub fn split_html_space_chars<'a>(s: &'a str) -> Filter<'a, &'a str, CharSplits<'a, StaticCharVec>> {
+ s.split(HTML_SPACE_CHARACTERS).filter(|&split| !split.is_empty())
+}