by devadvance · 7y ago · 0 comments
If you've ever noticed that entering an emoji or other non-ASCII [2] character seems to dramatically increase the size of your SMS, that's because the message is switching from 1-byte characters to 2-byte characters.
[1] https://www.twilio.com/docs/glossary/what-is-ucs-2-character...
[2] It's actually GSM-7, not ASCII, but the principle is the same: https://www.twilio.com/docs/glossary/what-is-gsm-7-character...
Every flip phone I owned did not play well with non-ASCII text. Receiving a message with an emoji would render the entire message, or if I was lucky just the portion following the emoji, unrenderable. Most phones I had failed to just rectangles, which I assume is their method of mojibake.
This was not a causal factor in my switch to a smartphone. It was annoying to have to explain character encodings to friends who didn't understand why they couldn't send me emoji-containing messages.
https://news.ycombinator.com/newsguidelines.html
You might also find these links helpful for getting the intended use of HN:
https://news.ycombinator.com/newswelcome.html
https://news.ycombinator.com/hackernews.html
What's cool is that UCS-2 and UTF-16 behave the same way in this regard, so you can see how this works in JavaScript as well. There's a great HN post about the length of an emoji being 2 in JS [1] from 2017.
Practically speaking, I had fun learning this while writing an Angular app to read SMS backups [2]. It's frustrating and cool at the same time.
[1] https://news.ycombinator.com/item?id=13830177
[2] https://github.com/devadvance/sms-backup-reader-2/blob/maste...
UTF-16 can represent all Unicode code points, through surrogate pairs when needed.
Systems that originally were designed for UCS-2 have often been upgraded to UTF-16. E.g. Windows, JS. But it is then not UCS-2 anymore. In some case the documentation and/or function names, etc., might talk incorrectly about being UCS-2 (while they really are UTF-16 now) for historical reasons, adding to the confusion.
>UCS-2 differs from UTF-16 by being a constant length encoding[4] and only capable of encoding characters of BMP.
https://en.wikipedia.org/wiki/UTF-16
There does seem to be some disagreement on this topic though. I wonder if it could be described as WTF-16.