# Corner-cases in \`Character\` classification of whitespace

**URL:** <https://forums.swift.org/t/corner-cases-in-character-classification-of-whitespace/12900>\
**Category:** Discussion\
**Created:** [May 22, 2018, 6:57pm UTC](https://forums.swift.org/t/corner-cases-in-character-classification-of-whitespace/12900 "2018-05-22T18:57:59Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![itaiferber](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/itaiferber/32/33840_2.png) [@itaiferber](https://forums.swift.org/u/itaiferber)\
**Post date:** [May 23, 2018, 5:25pm UTC](https://forums.swift.org/t/corner-cases-in-character-classification-of-whitespace/12900/24 "2018-05-23T17:25:22Z")

</div>

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?

```swift
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](https://forums.swift.org/t/pitch-character-and-string-properties/11620/66) in the [Character and String properties pitch](https://forums.swift.org/t/pitch-character-and-string-properties/11620/1), 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.

---

_[View the full topic](https://forums.swift.org/t/corner-cases-in-character-classification-of-whitespace/12900)._
