News for hackers. Stuff that matters.
Re:JavaScript string encoding by paulddraper on Sunday September 03, 2017 @07:51PM (#15164647)
> It seems to make the "newbie unicode error" of assuming that strings "have" an encoding

You imply that there is some universal "string" definition, when there is no such thing.

Literally, "string" just means sequence. Beyond that, it depends on the context.

* C++ std::string is a sequence of char (aka byte, defined to be 8+ bits).

* Swift string is a sequence of Unicode graphemes.

* Ruby String is a sequence of bytes/octects, with an attached (and mutable) encoding.

* Python 2 str is a sequence of bytes/octets

* Python 3 str is a sequence of Unicode code points

* ECMAScript string (and Java java.lang.String) is a sequence of UTF-16 code units.

Moreover, the entire idea of "Strings are an array of integer unicode code points" is confined to Unicode. It doesn't say anything about other character sets, e.g. ASCII, ISO 8859-1, or Windows-1252. (Though AFAIK Unicode is a superset of those particular three.)

So...I think you can safely say "Unicode strings are sequences of Unicode code points."

There are no comments on this comment yet.