Instead of prescribing what is and isn't whitespace by deciding on what trimming whitespace is meant to do, can we not sidestep this entire issue by offering the developer a choice?
enum WhitespaceOptions {
// Considers a `Character` to be whitespace if all of its underlying
// Unicode scalars are whitespace.
case hasAllWhitespace
// Considers a `Character` to be whitespace if any of its underlying
// Unicode scalars are whitespace.
case hasAnyWhitespace
}
extension String {
func trim(_ options: TrimOptions, whitespaceOptions: WhitespaceOptions = .hasAllWhitespace) { ... }
}
As I'd previously brought up in the Character and String properties pitch, whitespace has different meaning in different applications ("does not appear to draw anything" vs. "separates values" is just one distinction) and instead of trying to decide what whitespace means across the board, I think allowing the developer to meaningfully decide for themselves and the semantics they need is better for everyone.