UTF-8 String Indexing Strategies
One issue to consider is that strings typically feature random access indexing of code points with a time complexity resembling constant time ( ). Slices are still over bytes, but they “round up” to the end of the current code point:
Iterating over a string requires helper functions which keep an internal “bookmark” so that each access is constant time:
So Julia doesn’t pretend, it makes the problem explicit. A further case of the language favoring UTF-8 is that casting a string to decodes strings into code points, like UCS-4, again using :
So, like Julia, there’s no pretending, and the programmer explicitly must consider the problem.
Source: nullprogram.com