A function that removes on partial prefixes can be composed from the whole-prefix version along with a divergence-testing method.
uliwitness:
In particular, a way to iterate over a
String
and test whether a certain string or sequence from aCharacterSet
is present, and to also get theirRange
in theString
would 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.