5 ms·
Has Swift improved their text handling? Last time I looked, it took way too many lines of code and temporary variables just to extract a substring range from a
by developer2 7y ago
Has Swift improved their text handling? Last time I looked, it took way too many lines of code and temporary variables just to extract a substring range from a string. Their convoluted idea that a string can't be directly sliced with integer indexes–by bytes, let alone by Unicode code points or graphemes–was so frustrating I swore I would never look in Swift's general direction again. It was such a joke just to try to extract x UTF-8 characters starting from position y. I liked the overall feel of the language, but the fact I ran into such a horrible wall trying to perform the most basic of string manipulations was unforgivable.
Swift came out at a time where UTF-8 was already the standard. They talked a lot of talk about grapheme clusters being the most accurate representation, and then failed to deliver a coherent API to back it up. Any chance that has changed?
- skohan 7y agoIt's gotten a bit better, but Swift is still probably not the tool you want to use if you need to do a lot of string manipulation. Swift's string implementation has some interesting properties in terms of memory efficiency and performance, but it still requires fairly the verbose use of string indexes when working with strings rather than simple int offsets. There are good reasons for this, but it's not terribly ergonomic to work with. FWIW it would probably be fairly easy to implement some String extensions which would give you the kind of API it sounds like you are looking for.