4 ms·
That would require an array of 32 bit integers (basically UTF-32). It wastes a lot of space for most characters and doesn't help that much with indexing since u
by Ndymium 8y ago
That would require an array of 32 bit integers (basically UTF-32). It wastes a lot of space for most characters and doesn't help that much with indexing since user perceived characters can still be composed of many codepoints. Different languages take different approaches.
Python 3.3+, I believe, looks at the string and chooses ASCII/UCS-2/UCS-4 based on the character that takes the highest amount of bytes [1]. Elixir uses UTF-8 for strings (but you can get the codepoints easily), whereas Erlang uses the list of unicode ints style.
[1] https://www.b-list.org/weblog/2017/sep/05/how-python-does-unicode/ https://www.b-list.org/weblog/2017/sep/05/how-python-does-un...
- kizer 8y agoThanks for that link. It is very informative.