Can someone help me understand this commit
What is \u00A0 ?
The code strips trailing and leading space characters in addition to non breaking spaces, \u00A0
is the unicode point/code/number/alias for the non breaking space. You can pop up Firebug and type it out.
>>> '\u00A0'
" "
Further information about this character:
http://www.fileformat.info/info/unicode/char/00a0/index.htm
Edit: I just tried this code in Firebug, which checks for any matches from the generated non breaking space and it matched:
javascript:alert( String.fromCharCode(160).match(/\s/) )
However, upon doing this in IE6 it returns null
, so IE is most likely the reason for this update.
Update #2 - it looks like the removal of the caret makes this inconsistent with the previous version, because it removes not just leading and trailing spaces but spaces anywhere.
r = /(\s|\u00A0)+|(\s|\u00A0)+$/g;
s = ' wh at'
s = s.replace( r, '' )
Outputs
"what"
Looks like a Unicode space character which is NOT equivalent or equal to \u0020.
I'd guess that it's the same as String.fromCharCode(160)
from the test case - a non-breaking space. It's making sure that trim also trims off non-breaking space characters, which may not normally match the \s
character class.
It is the code point for the non-breaking space character in Unicode. The commit seems to work around a bug in Internet Explorer's JavaScript implementation where the \s
regular expression character class does not include \u00a0
.