From: Dr J R Stockton on
In comp.lang.javascript message <cmgjr51u7dk3iv6g7oke5fm544it90ppl9(a)4ax.
com>, Mon, 5 Apr 2010 14:51:08, Hans-Georg Michna <hans-
georgNoEmailPlease(a)michna.com> posted:

> I believe all functions in JavaScript that recognize
>white-space, like the regexp expressions \b and \s, recognize \r
>as white-space.

<URL:http://www.merlyn.demon.co.uk/js-valid.htm#RsT> tests the current
browser, and reports the results of my tests, for what \s (& \w)
recognises. Perhaps it should also test \b.

RegExp \s recognised Unicode hex 0009 000a 000b 000c 000d 0020 in all my
browsers, and it recognised each of 0009 000a 000b 000c 000d 0020
00a0 1680 180e 2000 2001 2002 2003 2004 2005 2006
2007 2008 2009 200a 200b 2028 2029 202f 205f 3000 in at least one of
them. IIRC, \r is 000d.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
From: Garrett Smith on
Hans-Georg Michna wrote:
> On Mon, 05 Apr 2010 14:00:06 -0700, Garrett Smith wrote:
>
>> Hans-Georg Michna wrote:
>
>>> /\bcollapsed\b/.test(p.className)
>
>> Oh, that's no good. \b matches "-".
>
> Dammit! Have to rewrite, and it's getting a little longer.
>

You can clean it up to a handful of lines.

> In the actual case it worked just fine, because there are no
> minus signs in the class attribute values. But that's no
> solution.
>
> So what would be the best way? Perhaps:
>
> /(^|\s)collapsed(\s|$)/.test(p.className)
>
> Seems a little more awkward, but what can we do?
>

Where supported, you can use HTML 5 DOMTokenList `element.classList`[1][2].

What you have works and is close what I use. I the RegExp constructor to
build a RegExp object using "(?:^|\s+)" + token + "(?:\s+|$)". I cache
the result in an object so if the function finds that there is already
one created, it just returns that object. I do this because usage
pattern results in the same regexp object being used over and over.

[1]https://developer.mozilla.org/en/DOM/element.classList
[2]http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#dom-classlist

I still get the javascript Error currentAlert is undefined on whatwg.org
http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2010-April/025814.html
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Lasse Reichstein Nielsen on
Dr J R Stockton <reply1014(a)merlyn.demon.co.uk> writes:

> <URL:http://www.merlyn.demon.co.uk/js-valid.htm#RsT> tests the current
> browser, and reports the results of my tests, for what \s (& \w)
> recognises. Perhaps it should also test \b.

Only if \b is expected to be broken, since \b is defined in terms of
word-characters (\w).
Are there any browsers that implement \w incorrectly (i.e., as anything
but [a-zA-Z0-9_])?

/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'

From: Swifty on
On Wed, 07 Apr 2010 00:25:56 +0200, Hans-Georg Michna
<hans-georgNoEmailPlease(a)michna.com> wrote:

>Such arguments are necessarily weak and theoretical. HTML is so
>messy in almost all web pages that it seems crazy to become
>religious about it. (:-)

I'm depending on this. There will always be millions of webpages worse
than mine. At least I'm trying to improve.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
From: Dr J R Stockton on
In comp.lang.javascript message <vwu7R6II72uLFwhd(a)invalid.uk.co.demon.me
rlyn.invalid>, Tue, 6 Apr 2010 18:26:32, Dr J R Stockton
<reply1014(a)merlyn.demon.co.uk> posted:
>In comp.lang.javascript message <cmgjr51u7dk3iv6g7oke5fm544it90ppl9(a)4ax.
>com>, Mon, 5 Apr 2010 14:51:08, Hans-Georg Michna <hans-
>georgNoEmailPlease(a)michna.com> posted:
>
>> I believe all functions in JavaScript that recognize
>>white-space, like the regexp expressions \b and \s, recognize \r
>>as white-space.
>
><URL:http://www.merlyn.demon.co.uk/js-valid.htm#RsT> tests the current
>browser, and reports the results of my tests, for what \s (& \w)
>recognises. Perhaps it should also test \b.

And now it does. In the string "\u0000 ... \uFFFF", my default Firefox
Opera Safari Chrome find 8 matches to \b but IE 8 finds 10. As they all
look like "", I don't know where they are as yet.

Moreover, in those 4 \w matches 63 characters but in IE 8 it matches 64;
the extra being capital I with dot above (new in IE 8, ?). Perhaps the
omission of lower-case dot-less i is unintentional. ECMA 3, ISO, ECMA 5
require sixty-three characters.

Consider <http://en.wikipedia.org/wiki/%C4%B0>.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)