String hygiene

I wasn't actually sure what the standard library rule is for returning a String vs a Substring, so I looked into it. Given that drop(while:), dropFirst(), dropFirst(_:), dropLast(), dropLast(_:), subscript(_:), prefix(_:), prefix(through:), prefix(upTo:), prefix(while:), suffix(_:), suffix(from:), split(separator:maxSplits:omittingEmptySubsequences:) and split(maxSplits:omittingEmptySubsequences:whereSeparator:) all return Substring (or an Array thereof), it seems obvious to me that any trim method(s) should also return Substring.

Looking at the various remove methods, it's also clear that the in-place version, trim(from:), probably shouldn't return self.

3 Likes