1111
1212import _StringProcessing
1313
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+
1419extension BidirectionalCollection where SubSequence == Substring {
1520 /// Matches a regex in its entirety, where the regex is created by
1621 /// the given closure.
@@ -94,10 +99,10 @@ extension BidirectionalCollection where SubSequence == Substring {
9499 /// - Returns: A collection of substrings, split from this collection's
95100 /// elements.
96101 @available ( SwiftStdlib 5 . 7 , * )
97- public func split(
102+ public func split< R : RegexComponent > (
98103 maxSplits: Int = Int . max,
99104 omittingEmptySubsequences: Bool = true ,
100- @RegexComponentBuilder separator: ( ) -> some RegexComponent
105+ @RegexComponentBuilder separator: ( ) -> R
101106 ) -> [ SubSequence ] {
102107 split ( separator: separator ( ) , maxSplits: maxSplits, omittingEmptySubsequences: omittingEmptySubsequences)
103108 }
@@ -191,11 +196,11 @@ where Self: BidirectionalCollection, SubSequence == Substring {
191196 /// - Returns: A new collection in which all matches for regex in `subrange`
192197 /// are replaced by `replacement`, using `content` to create the regex.
193198 @available ( SwiftStdlib 5 . 7 , * )
194- public func replacing< Replacement: Collection > (
199+ public func replacing< R : RegexComponent , Replacement: Collection > (
195200 with replacement: Replacement ,
196201 subrange: Range < Index > ,
197202 maxReplacements: Int = . max,
198- @RegexComponentBuilder content: ( ) -> some RegexComponent
203+ @RegexComponentBuilder content: ( ) -> R
199204 ) -> Self where Replacement. Element == Element {
200205 replacing ( content ( ) , with: replacement, subrange: subrange, maxReplacements: maxReplacements)
201206 }
@@ -213,10 +218,10 @@ where Self: BidirectionalCollection, SubSequence == Substring {
213218 /// - Returns: A new collection in which all matches for regex in `subrange`
214219 /// are replaced by `replacement`, using `content` to create the regex.
215220 @available ( SwiftStdlib 5 . 7 , * )
216- public func replacing< Replacement: Collection > (
221+ public func replacing< R : RegexComponent , Replacement: Collection > (
217222 with replacement: Replacement ,
218223 maxReplacements: Int = . max,
219- @RegexComponentBuilder content: ( ) -> some RegexComponent
224+ @RegexComponentBuilder content: ( ) -> R
220225 ) -> Self where Replacement. Element == Element {
221226 replacing ( content ( ) , with: replacement, maxReplacements: maxReplacements)
222227 }
@@ -232,10 +237,10 @@ where Self: BidirectionalCollection, SubSequence == Substring {
232237 /// - content: A closure that returns the collection to search for
233238 /// and replace.
234239 @available ( SwiftStdlib 5 . 7 , * )
235- public mutating func replace< Replacement: Collection > (
240+ public mutating func replace< R : RegexComponent , Replacement: Collection > (
236241 with replacement: Replacement ,
237242 maxReplacements: Int = . max,
238- @RegexComponentBuilder content: ( ) -> some RegexComponent
243+ @RegexComponentBuilder content: ( ) -> R
239244 ) where Replacement. Element == Element {
240245 replace ( content ( ) , with: replacement, maxReplacements: maxReplacements)
241246 }
0 commit comments