JavaScript’s internal character encoding: UCS-2 or UTF-16?
mathiasbynens.be
mathiasbynens.be
UCS-2 is not an encoding that is generally compatible with Unicode. It's kind of like saying that 7-bit ASCII and UTF-8 are character encodings for Unicode.
They can only encode a subset of Unicode, sure, but they’re still character encodings for Unicode, right?
From the Unicode website (http://www.unicode.org/faq/utf_bom.html#UTF8): "UTF-8 is the byte-oriented encoding form of Unicode."
From Wikipedia (http://en.wikipedia.org/wiki/UTF-8): "UTF-8 (UCS Transformation Format — 8-bit[1]) is a variable-width encoding that can represent every character in the Unicode character set."
from the article.
"It produces a variable-length result of either one or two 16-bit code units per code point" from wikipedia.org
I feel this should have been quoted or referenced in some way in the article. Or it might just be a very rare case of coincidence.http://wiki.ecmascript.org/doku.php?id=strawman:support_full...
Also, Windows has some problems with UTF-8 due to MB_LEN_MAX[0] being 2. Which cannot be changed because that would break the ABI. (e.g. "char foo[MB_LEN_MAX * len + 1];") Those problems aren't totally insurmountable as Windows does have UTF-8 code pages which work, but it's not totally plain sailing.
In any case, going back now would be an admission of a mistake.
Thus, Windows is UTF-16. And the infection spreads....
[0] http://www.kernel.org/doc/man-pages/online/pages/man3/MB_LEN...
JavaScript’s internal encoding is closer to UCS-2 than it is to UTF-16, but it doesn’t guarantee that a string is valid UCS-2 (or valid UTF-16).
JavaScript strings are like UCS-2, except that they allow surrogate characters.