I am wondering why unicode encoding is necessary in JavaScript. I am looking at utf8.js as an example. I am also looking at the utf8 spec, but am not really following the different pieces of data. Also, I don't fully understand when and where you are supposed to encode/decode, and what the "current" format is of some set of bytes in a programming language, so that's making it difficult to follow this.
UTF-8’s encoder’s handler, given a stream and code point, runs these steps:...
I would like to know what the stream is, and what the code point is. I understand that code points are characters, which in utf8 might be composed of multiple 8-bit code units.
I would also just generally like to know why you can't just have in a language "unicode", and there is no utf8/utf16 encoding/decoding, because it is already in let's say utf8 format. This makes me wonder if JavaScript needs to do this encoding/decoding for some reason, such as maybe because JavaScript uses utf16 encoding, and so the stream of bits you pass to utf8.js is a stream of utf16 encoded bits. Or maybe it's not that, and instead the stream of bits you pass to utf8.js is a stream of x
(something else) such as decimal encoding or whatever that may mean.
I am just not sure what format/encoding the bytes are coming in as, and also why we need to do the conversion. For example, in here when they mention the "Buffer class is ... raw binary data" (in Node.js), I am not sure what that raw binary data means. Maybe that just means it is UTF16, which is why it would then maybe need to be converted to UTF8, I am not sure. And when this mentions JSON.parse
doesn't do any string decoding, I start to wonder if this means that JSON.parse
assumes UTF16 encoding, or perhaps it assumes UTF8 encoding, I'm not sure. Searching for the "encoding JSON.parse
uses" doesn't reveal anything.