For some reason, I always end up parsing things. Currently, the APIs are not well suited for this. Ideally, at some future point, we’d have something like Perl 6 grammars (I would love this).
Today, I write most of my methods as
mutating func on
Substring. I think the stdlib could benefit from having more of these. Things like
func removePrefix(_ str: String) -> Bool, etc. Basically, a lot of stuff similar to Foundation’s Scanner.
I’m wondering if, as a first step towards better string processing, we could make a list of these kinds of methods that mutate substrings. They might also be defined on protocols instead (so that we can also easily parse things like Data). I imagine that, even if we someday arrive at having embedded grammars, these methods would still be useful.
What do y’all think of this? Which kind of methods do you keep writing?