3 ms·
> how would I properly iterate through Unicode? Either you use a (big, complex) library like ICU or you just don't. People have been thought for too long that
by qalmakka 3y ago
> how would I properly iterate through Unicode?
Either you use a (big, complex) library like ICU or you just don't.
People have been thought for too long that strings are arrays of characters - they are not, they are array of bytes, and bytes may mean lots of things.
If you need to iterate or randomly access a string you should ask yourself why are you doing it. Any code that attempts to operate on codepoints will inevitably only ever work properly for ASCII. If that's fine for you (for instance, you want to match all text between a pair of <>) then you can probably work on raw bytes and UTF-8. If that's not the case, you need a library to handle the million different cases related to supporting RTL, invisible characters, pictograms, combinations, ...
Never use wchar_t, and even things like char16_t and char32_t have very few correct usecases to be honest (like implementing computing sizes, etc).
Even counting characters is broken, `wcslen(L"Salò")` may still be 4 or 5 depending on the current normalization form. The correct solution is to take strings as black boxes, array of bytes you only access through APIs (like binary data).
It is also high time we get rid of obsolete concepts like case sensivity - it just doesn't work at all outside of regional code pages (try doing `"ciao".toUpperCase().equals("CIAO")` in Java with locale tr_TR.UTF-8 and look what happens).