A function that removes on partial prefixes can be composed from the whole-prefix version along with a divergence-testing method.
In particular, a way to iterate over a
Stringand test whether a certain string or sequence from aCharacterSetis present, and to also get theirRangein theStringwould be really helpful. Something likeextension String { func extractIf(prefix: String, in range: inout Range) -> (String, Range)? func extracLongesttIf(prefixFrom: CharacterSet, in range: inout Range) -> (String, Range)? }
extractIf could be done with a divergence-testing function too. extractLongestIf could be adapted from self.firstIndex(where: { !prefixFrom.contains($0) }). Neither requires String; they should be added to Collection in general.