r/ProgrammingLanguages • • 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

76 comments sorted by

View all comments

Show parent comment

1

u/hgs3 May 24 '26

Yes anything in the basic multilingual plane, excluding surrogates, can be indexed. ASCII is just where the overlap is with UTF-8.

I don’t think there’s any standardized way to refer to column indices. The most correct approach is to write the grapheme index since that’s what the user visually sees.

The problem with reporting code units is (1) it leaks an implementation detail of the compiler and (2) code points encoded with multiple code units will be incorrectly reported. It would be more correct to report the code point index as that (1) doesn’t leak implementation details and (2) that’s how Unicode defines what a “character” is. But it still won’t necessarily be visually correct for multi-code-point graphemes.