|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 |
| -/// Trims leading and trailing whitespace from each line. |
14 |
| -public func dedented<Lines: Sequence>(lines: Lines) -> [String] where Lines.Element: StringProtocol { |
15 |
| - lines.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } |
| 13 | +extension Sequence where Element: StringProtocol { |
| 14 | + /// Trims leading and trailing whitespace from each line. |
| 15 | + var dedented: [String] { |
| 16 | + return self.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } |
| 17 | + } |
16 | 18 | }
|
17 | 19 |
|
18 |
| -/// Trims leading and trailing whitespace from each line. |
19 |
| -public func dedented(string: String) -> String { |
20 |
| - dedented(lines: string.split(separator: "\n")) |
21 |
| - .joined(separator: "\n") |
22 |
| -} |
| 20 | +extension String { |
| 21 | + /// Trims leading and trailing whitespace from each line. |
| 22 | + public var dedented: String { |
| 23 | + return self.split(separator: "\n") |
| 24 | + .dedented |
| 25 | + .joined(separator: "\n") |
| 26 | + } |
23 | 27 |
|
24 |
| -/// Creates a single-line documentation string from indented |
25 |
| -/// documentation as written in `CodeGeneration`. |
26 |
| -public func flattened(indentedDocumentation: String) -> String { |
27 |
| - dedented(string: indentedDocumentation) |
28 |
| - .replacingOccurrences(of: "\n", with: "") |
29 |
| - .trimmingCharacters(in: .whitespacesAndNewlines) |
30 |
| -} |
| 28 | + /// Creates a single-line documentation string from indented |
| 29 | + /// documentation as written in `CodeGeneration`. |
| 30 | + public var flattened: String { |
| 31 | + self |
| 32 | + .dedented |
| 33 | + .replacingOccurrences(of: "\n", with: "") |
| 34 | + .trimmingCharacters(in: .whitespacesAndNewlines) |
| 35 | + } |
31 | 36 |
|
32 |
| -/// Removes all empty lines from a multi-line string. |
33 |
| -public func removedEmptyLines(string: String) -> String { |
34 |
| - string.split(whereSeparator: \.isNewline) |
35 |
| - .filter { !$0.allSatisfy(\.isWhitespace) } |
36 |
| - .joined(separator: "\n") |
| 37 | + /// Removes all empty lines from a multi-line string. |
| 38 | + public var removingEmptyLines: String { |
| 39 | + return |
| 40 | + self |
| 41 | + .split(whereSeparator: \.isNewline) |
| 42 | + .filter { !$0.allSatisfy(\.isWhitespace) } |
| 43 | + .joined(separator: "\n") |
| 44 | + } |
37 | 45 | }
|
0 commit comments