Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Javascript uses UCS-2 internally, which is not UTF-16. It is very difficult to handle Unicode in Javascript because of this, and I do not suggest attempting to do so.</p> <p>As for what Twitter does, you seem to be saying that it is sanely counting by code point not insanely by code unit.</p> <p>Unless you have no choice, you should use a programming language that actually supports Unicode, and which has a code-point interface, not a code-unit interface. Javascript isn't good enough for that as you have discovered. </p> <p>It has <em>The UCS-2 Curse,</em> which is even worse than <em>The UTF-16 Curse,</em> which is already bad enough. I talk about all this in OSCON talk, <a href="http://training.perl.com/OSCON2011/index.html"> Unicode Support Shootout: The Good, the Bad, &amp; the (mostly) Ugly </a>. </p> <p>Due to its horrible Curse, you have to hand-simulate UTF-16 with UCS-2 in Javascript, which is simply nuts. </p> <p>Javascript suffers from all kinds of other terrible Unicode troubles, too. It has no support for graphemes or normalization or collation, all of which you really need. And its regexes are broken, sometimes due to the Curse, sometimes just because people got it wrong. For example, Javascript is incapable of expressing regexes like <code>[-]</code>. Javascript doesn’t even support casefolding, so you can’t write a pattern like <code>/ΣΤΙΓΜΑΣ/i</code> and have it correctly match <em>στιγμας</em>.</p> <p>You can try to use <a href="http://xregexp.com/plugins/">the XRegEXp plugin</a>, but you won’t banish the Curse that way. Only changing to a language with Unicode support will do that, and just isn’t one of those.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload