aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/attr.rs
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno.d@partner.samsung.com>2014-08-12 10:58:18 -0400
committerBruno de Oliveira Abinader <bruno.d@partner.samsung.com>2014-08-25 13:58:42 -0400
commite9f9afc32416b6452676ee668c12069afcbd7cd4 (patch)
tree66f954fd21675a8786a2704c6363d4dcab85a89c /src/components/script/dom/attr.rs
parent592454defd39e0d186fe8b7e046f2b31e2454e0e (diff)
downloadservo-e9f9afc32416b6452676ee668c12069afcbd7cd4.tar.gz
servo-e9f9afc32416b6452676ee668c12069afcbd7cd4.zip
Implemented Attribute's tokens() iterator
Diffstat (limited to 'src/components/script/dom/attr.rs')
-rw-r--r--src/components/script/dom/attr.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs
index d31250fb0ee..9f3fc9dc96e 100644
--- a/src/components/script/dom/attr.rs
+++ b/src/components/script/dom/attr.rs
@@ -16,9 +16,10 @@ use dom::virtualmethods::vtable_for;
use servo_util::atom::Atom;
use servo_util::namespace;
use servo_util::namespace::Namespace;
-use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
+use servo_util::str::{DOMString, split_html_space_chars};
use std::cell::{Ref, RefCell};
use std::mem;
+use std::slice::Items;
pub enum AttrSettingType {
FirstSetAttr,
@@ -28,27 +29,16 @@ pub enum AttrSettingType {
#[deriving(PartialEq, Clone, Encodable)]
pub enum AttrValue {
StringAttrValue(DOMString),
- TokenListAttrValue(DOMString, Vec<(uint, uint)>),
+ TokenListAttrValue(DOMString, Vec<Atom>),
UIntAttrValue(DOMString, u32),
AtomAttrValue(Atom),
}
impl AttrValue {
- pub fn from_tokenlist(list: DOMString) -> AttrValue {
- let mut indexes = vec![];
- let mut last_index: uint = 0;
- let length = list.len() - 1;
- for (index, ch) in list.as_slice().char_indices() {
- if HTML_SPACE_CHARACTERS.iter().any(|&space| space == ch) {
- if last_index != index {
- indexes.push((last_index, index));
- }
- last_index = index + 1;
- } else if index == length {
- indexes.push((last_index, index + 1));
- }
- }
- return TokenListAttrValue(list, indexes);
+ pub fn from_tokenlist(tokens: DOMString) -> AttrValue {
+ let atoms = split_html_space_chars(tokens.as_slice())
+ .map(|token| Atom::from_slice(token)).collect();
+ TokenListAttrValue(tokens, atoms)
}
pub fn from_u32(string: DOMString, default: u32) -> AttrValue {
@@ -61,6 +51,12 @@ impl AttrValue {
AtomAttrValue(value)
}
+ pub fn tokens<'a>(&'a self) -> Option<Items<'a, Atom>> {
+ match *self {
+ TokenListAttrValue(_, ref tokens) => Some(tokens.iter()),
+ _ => None
+ }
+ }
}
impl Str for AttrValue {