11
11
12
12
import _StringProcessing
13
13
14
+ // FIXME(rdar://92459215): We should be using 'some RegexComponent' instead of
15
+ // <R: RegexComponent> for the methods below that don't impose any additional
16
+ // requirements on the type. Currently the generic parameter is needed to work
17
+ // around a compiler issue.
18
+
14
19
extension BidirectionalCollection where SubSequence == Substring {
15
20
/// Matches a regex in its entirety, where the regex is created by
16
21
/// the given closure.
@@ -94,10 +99,10 @@ extension BidirectionalCollection where SubSequence == Substring {
94
99
/// - Returns: A collection of substrings, split from this collection's
95
100
/// elements.
96
101
@available ( SwiftStdlib 5 . 7 , * )
97
- public func split(
102
+ public func split< R : RegexComponent > (
98
103
maxSplits: Int = Int . max,
99
104
omittingEmptySubsequences: Bool = true ,
100
- @RegexComponentBuilder separator: ( ) -> some RegexComponent
105
+ @RegexComponentBuilder separator: ( ) -> R
101
106
) -> [ SubSequence ] {
102
107
split ( separator: separator ( ) , maxSplits: maxSplits, omittingEmptySubsequences: omittingEmptySubsequences)
103
108
}
@@ -191,11 +196,11 @@ where Self: BidirectionalCollection, SubSequence == Substring {
191
196
/// - Returns: A new collection in which all matches for regex in `subrange`
192
197
/// are replaced by `replacement`, using `content` to create the regex.
193
198
@available ( SwiftStdlib 5 . 7 , * )
194
- public func replacing< Replacement: Collection > (
199
+ public func replacing< R : RegexComponent , Replacement: Collection > (
195
200
with replacement: Replacement ,
196
201
subrange: Range < Index > ,
197
202
maxReplacements: Int = . max,
198
- @RegexComponentBuilder content: ( ) -> some RegexComponent
203
+ @RegexComponentBuilder content: ( ) -> R
199
204
) -> Self where Replacement. Element == Element {
200
205
replacing ( content ( ) , with: replacement, subrange: subrange, maxReplacements: maxReplacements)
201
206
}
@@ -213,10 +218,10 @@ where Self: BidirectionalCollection, SubSequence == Substring {
213
218
/// - Returns: A new collection in which all matches for regex in `subrange`
214
219
/// are replaced by `replacement`, using `content` to create the regex.
215
220
@available ( SwiftStdlib 5 . 7 , * )
216
- public func replacing< Replacement: Collection > (
221
+ public func replacing< R : RegexComponent , Replacement: Collection > (
217
222
with replacement: Replacement ,
218
223
maxReplacements: Int = . max,
219
- @RegexComponentBuilder content: ( ) -> some RegexComponent
224
+ @RegexComponentBuilder content: ( ) -> R
220
225
) -> Self where Replacement. Element == Element {
221
226
replacing ( content ( ) , with: replacement, maxReplacements: maxReplacements)
222
227
}
@@ -232,10 +237,10 @@ where Self: BidirectionalCollection, SubSequence == Substring {
232
237
/// - content: A closure that returns the collection to search for
233
238
/// and replace.
234
239
@available ( SwiftStdlib 5 . 7 , * )
235
- public mutating func replace< Replacement: Collection > (
240
+ public mutating func replace< R : RegexComponent , Replacement: Collection > (
236
241
with replacement: Replacement ,
237
242
maxReplacements: Int = . max,
238
- @RegexComponentBuilder content: ( ) -> some RegexComponent
243
+ @RegexComponentBuilder content: ( ) -> R
239
244
) where Replacement. Element == Element {
240
245
replace ( content ( ) , with: replacement, maxReplacements: maxReplacements)
241
246
}
0 commit comments