The idea is to add a helper for parser combinator-like things. Currently, I have to do something like the following:
extension StringProtocol {
func suffix(after prefix: StringProtocol) -> Substring? {
guard hasPrefix(prefix) else { return nil }
let suffixIndex = self.index(startIndex, offsetBy: prefix.characters.count)
return self[suffixIndex...]
}
}
(Modified from SuperCombinators/StringParsing.swift at master · superlopuh/SuperCombinators · GitHub)
This has two expensive string operations, that could be reduced to one if the hasPrefix call included the result of the computation. I hope that the String interface hasn't been set in stone yet, and that I'll be able to sneak this in.
An alternative would be to provide an optional index after the prefix instead of the substring.
Ideally, this would be a bit like the arithmetic operations that have hidden variants with overflow as a part of the result.