aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/attr.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2014-12-26 13:18:45 -0700
committerbors-servo <metajack+bors@gmail.com>2014-12-26 13:18:45 -0700
commit3af73e9962fe810de0c556693ec2eb0559b06a67 (patch)
tree3a6220ae9a6c05c5b43bdf5fc6f822e597e39d7a /components/script/dom/attr.rs
parent0e6304dcf7fd6712f4455151b55a361de857359d (diff)
parent3624673d2faf7a36face3321af70fc55117a24a7 (diff)
downloadservo-3af73e9962fe810de0c556693ec2eb0559b06a67.tar.gz
servo-3af73e9962fe810de0c556693ec2eb0559b06a67.zip
auto merge of #4353 : brunoabinader/servo/domtokenlist, r=Ms2ger
Specs: https://dom.spec.whatwg.org/#dom-domtokenlist-add https://dom.spec.whatwg.org/#dom-domtokenlist-remove https://dom.spec.whatwg.org/#dom-domtokenlist-toggle https://dom.spec.whatwg.org/#concept-dtl-update https://dom.spec.whatwg.org/#concept-ordered-set-serializer Closes #3138.
Diffstat (limited to 'components/script/dom/attr.rs')
-rw-r--r--components/script/dom/attr.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index d1b288bd7ad..014fa5f5357 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -37,9 +37,21 @@ pub enum AttrValue {
}
impl AttrValue {
- pub fn from_tokenlist(tokens: DOMString) -> AttrValue {
- let atoms = split_html_space_chars(tokens.as_slice())
- .map(|token| Atom::from_slice(token)).collect();
+ pub fn from_serialized_tokenlist(tokens: DOMString) -> AttrValue {
+ let mut atoms: Vec<Atom> = vec!();
+ for token in split_html_space_chars(tokens.as_slice()).map(|slice| Atom::from_slice(slice)) {
+ if !atoms.iter().any(|atom| *atom == token) {
+ atoms.push(token);
+ }
+ }
+ AttrValue::TokenList(tokens, atoms)
+ }
+
+ pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
+ let tokens = {
+ let slices: Vec<&str> = atoms.iter().map(|atom| atom.as_slice()).collect();
+ slices.connect("\x20")
+ };
AttrValue::TokenList(tokens, atoms)
}