Improve [attr~="value"] selector (attribute contains word)
authorJakub Narebski <jnareb@gmail.com>
Mon, 24 Jan 2011 12:04:33 +0000 (13:04 +0100)
committerJakub Narebski <jnareb@gmail.com>
Mon, 24 Jan 2011 12:04:33 +0000 (13:04 +0100)
commitf7dc3b611fcb491ad708b7f71347d36bad71fb1c
tree2e809ac44c6ac871928df6822901e885d878e136
parent8af6dead371dda2793a0649592cfa0dcf905e5bc
Improve [attr~="value"] selector (attribute contains word)

Instead of first splitting attribute value into words, and then
checking that one of words is equal to given value

   grep { $_ eq $value } split ' ', $attr;

use regexp anchored to words boundary for word matching

   /\b\Q$value\E\b/

Strictly speaking it makes [attr=~"value"] selector not conformant to
CSS2+ specification, but it shouldn't matter in real life.  See
http://www.w3.org/TR/CSS2/selector.html#attribute-selectors

  [att~=val]

     [..] If "val" contains white space, it will never represent anything
     (since the words are separated by spaces). If "val" is the empty
     string, it will never represent anything either.

Suggested-by: Matt S Trout <mst@shadowcat.co.uk>
lib/HTML/Zoom/SelectorParser.pm