r/ProgrammingLanguages • u/funcieq • May 23 '26
Discussion How to implement String?
Currently, String in my language is just value and length because it's a temporary solution, And as the language has developed, I am now able to rewrite a lot just for it, so I want to make a decent String in my language. So my question is, which String concept annoys you the least?
47
Upvotes
View all comments
Show parent comment
1
u/prehensilemullet May 24 '26 edited May 24 '26
Well not just ASCII… looking for anything in the basic multilingual plane, except code units in the range for surrogate pairs, should work with indexing by code unit in UTF-16, right? Making it more flexible for that purpose than UTF-8, where only ASCII is single code units
For example, parsers will typically output line/column ranges of AST nodes and errors, and I’m sure many naively use the code unit index offsets for columns. If a line contains emoji, columns based upon code unit index are definitely going to be wrong after that. And if using UTF-8, anything not ASCII would corrupt the column indexes. But with UTF-16 code could contain text in many languages without corrupting column indexes from this naive approach.
Now I’m wondering how many parsers actually go to the trouble to output true character indexes for columns, since that takes extra computation