mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implemented Attribute's tokens() iterator
This commit is contained in:
parent
592454defd
commit
e9f9afc324
1 changed files with 13 additions and 17 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue