Skip to content

Commit 1abdcab

Browse files
committed
update wrapping
1 parent 80f6c7e commit 1abdcab

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

Documentation/Evolution/StringProcessingAlgorithms.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
The standard library is currently missing a large number of `String` algorithms that do exist in Foundation. We introduce a more coherent set of `Collection` algorithms with a focus on string processing, including support for regular expressions.
66

7+
78
## Motivation
89

910
TODO: Motivation for adding both generic `<r: RegexProtocol>` and non-generic algorithm functions.
1011

1112

1213
### Use custom parsers in regex builders and `RegexProtocol` algorithms
1314

14-
It would be handy if you can use types from outside the standard library in regex builders and `RegexProtocol` algorithms.
15+
We want to extend string processing to types from outside the standard library, so that one can incorporate custom parsers in regex builders and `RegexProtocol` algorithms seamlessly.
1516

1617
Consider parsing an HTTP header to capture the date field as a `Date` type:
1718

@@ -105,17 +106,21 @@ The following algorithms are included in this pitch:
105106

106107
```swift
107108
extension Collection where Element: Equatable {
108-
/// Returns a Boolean value indicating whether the collection contains the given sequence.
109+
/// Returns a Boolean value indicating whether the collection contains the
110+
/// given sequence.
109111
/// - Parameter other: A sequence to search for within this collection.
110-
/// - Returns: `true` if the collection contains the specified sequence, otherwise `false`.
112+
/// - Returns: `true` if the collection contains the specified sequence,
113+
/// otherwise `false`.
111114
public func contains<S: Sequence>(_ other: S) -> Bool
112115
where S.Element == Element
113116
}
114117

115118
extension BidirectionalCollection where SubSequence == Substring {
116-
/// Returns a Boolean value indicating whether the collection contains the given regex.
119+
/// Returns a Boolean value indicating whether the collection contains the
120+
/// given regex.
117121
/// - Parameter regex: A regex to search for within this collection.
118-
/// - Returns: `true` if the regex was found in the collection, otherwise `false`.
122+
/// - Returns: `true` if the regex was found in the collection, otherwise
123+
/// `false`.
119124
public func contains<R: RegexProtocol>(_ regex: R) -> Bool
120125
}
121126
```
@@ -124,9 +129,11 @@ extension BidirectionalCollection where SubSequence == Substring {
124129

125130
```swift
126131
extension BidirectionalCollection where SubSequence == Substring {
127-
/// Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in the specified regex.
132+
/// Returns a Boolean value indicating whether the initial elements of the
133+
/// sequence are the same as the elements in the specified regex.
128134
/// - Parameter regex: A regex to compare to this sequence.
129-
/// - Returns: `true` if the initial elements of the sequence matches the beginning of `regex`; otherwise, `false`.
135+
/// - Returns: `true` if the initial elements of the sequence matches the
136+
/// beginning of `regex`; otherwise, `false`.
130137
public func starts<R: RegexProtocol>(with regex: R) -> Bool
131138
}
132139
```
@@ -135,21 +142,31 @@ extension BidirectionalCollection where SubSequence == Substring {
135142

136143
```swift
137144
extension Collection {
138-
/// Returns a new collection of the same type by removing initial elements that satisfy the given predicate from the start
139-
/// - Parameter predicate: A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be removed from the collection.
140-
/// - Returns: A collection containing the elements of the receiver that are not removed by `predicate`.
145+
/// Returns a new collection of the same type by removing initial elements
146+
/// that satisfy the given predicate from the start
147+
/// - Parameter predicate: A closure that takes an element of the sequence
148+
/// as its argument and returns a Boolean value indicating whether the
149+
/// element should be removed from the collection.
150+
/// - Returns: A collection containing the elements of the receiver that are
151+
/// not removed by `predicate`.
141152
public func trimmingPrefix(while predicate: (Element) -> Bool) -> SubSequence
142153
}
143154

144155
extension Collection where SubSequence == Self {
145-
/// Removes the initial elements that satisfy the given predicate from the start of the sequence.
146-
/// - Parameter predicate: A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be removed from the collection.
156+
/// Removes the initial elements that satisfy the given predicate from the
157+
/// start of the sequence.
158+
/// - Parameter predicate: A closure that takes an element of the sequence
159+
/// as its argument and returns a Boolean value indicating whether the
160+
/// element should be removed from the collection.
147161
public mutating func trimPrefix(while predicate: (Element) -> Bool)
148162
}
149163

150164
extension RangeReplaceableCollection {
151-
/// Removes the initial elements that satisfy the given predicate from the start of the sequence.
152-
/// - Parameter predicate: A closure that takes an element of the sequence as its argument and returns a Boolean value indicating whether the element should be removed from the collection.
165+
/// Removes the initial elements that satisfy the given predicate from the
166+
/// start of the sequence.
167+
/// - Parameter predicate: A closure that takes an element of the sequence
168+
/// as its argument and returns a Boolean value indicating whether the
169+
/// element should be removed from the collection.
153170
public mutating func trimPrefix(while predicate: (Element) -> Bool)
154171
}
155172

0 commit comments

Comments
 (0)