4 ms·
No, it's not overengineering. It's working with unicode. You have to let go of the idea that a string is a sequence of characters separated by where your cursor
by fingerlocks 5y ago
No, it's not overengineering. It's working with unicode. You have to let go of the idea that a string is a sequence of characters separated by where your cursor pauses. It's not. Black Santa was a simple metaphor for more real-world scenarios such the chinese language, in which multiple characters form to create a new character.
Imagine if you had a Color key on your keyboard, and a Santa key on your keyboard. Each key individually has meaning. When the two characters are positioned adjacent to each other, you get SkinColorSanta as one single character.
What is the new length of your string? Two for each original Color and Santa characters? Or 1 because there is only one icon the represents the two together? Remember Swift interops with C, so what is the size when you need to drop to char*? Hope you don't plan to use 1!
How would you solve this problem? Swift is open source. Make a PR if you have a better solution.
- selcuka 5y agoI'm not sure if we are on the same page. I am simply talking about syntactic sugar, not semantics. To restate, I still don't understand why you think str.dropFirst(1).dropLast(2) handles unicode better than str[1:-2] What does dropFirst(1) drop if the first _element_ is a Black Santa? Why can't whatever it does be implemented using the bracket syntax?