1212// MARK: `CollectionSearcher` algorithms
1313
1414extension RangeReplaceableCollection {
15- public func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
15+ func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
1616 _ searcher: Searcher ,
1717 with replacement: Replacement ,
1818 subrange: Range < Index > ,
@@ -36,7 +36,7 @@ extension RangeReplaceableCollection {
3636 return result
3737 }
3838
39- public func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
39+ func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
4040 _ searcher: Searcher ,
4141 with replacement: Replacement ,
4242 maxReplacements: Int = . max
@@ -50,7 +50,7 @@ extension RangeReplaceableCollection {
5050 maxReplacements: maxReplacements)
5151 }
5252
53- public mutating func replace<
53+ mutating func replace<
5454 Searcher: CollectionSearcher , Replacement: Collection
5555 > (
5656 _ searcher: Searcher ,
@@ -67,6 +67,16 @@ extension RangeReplaceableCollection {
6767// MARK: Fixed pattern algorithms
6868
6969extension RangeReplaceableCollection where Element: Equatable {
70+ /// Returns a new collection in which all occurrences of a target sequence
71+ /// are replaced by another collection.
72+ /// - Parameters:
73+ /// - other: The sequence to replace.
74+ /// - replacement: The new elements to add to the collection.
75+ /// - subrange: The range in the collection in which to search for `other`.
76+ /// - maxReplacements: A number specifying how many occurrences of `other`
77+ /// to replace. Default is `Int.max`.
78+ /// - Returns: A new collection in which all occurrences of `other` in
79+ /// `subrange` of the collection are replaced by `replacement`.
7080 public func replacing< S: Sequence , Replacement: Collection > (
7181 _ other: S ,
7282 with replacement: Replacement ,
@@ -79,7 +89,16 @@ extension RangeReplaceableCollection where Element: Equatable {
7989 subrange: subrange,
8090 maxReplacements: maxReplacements)
8191 }
82-
92+
93+ /// Returns a new collection in which all occurrences of a target sequence
94+ /// are replaced by another collection.
95+ /// - Parameters:
96+ /// - other: The sequence to replace.
97+ /// - replacement: The new elements to add to the collection.
98+ /// - maxReplacements: A number specifying how many occurrences of `other`
99+ /// to replace. Default is `Int.max`.
100+ /// - Returns: A new collection in which all occurrences of `other` in
101+ /// `subrange` of the collection are replaced by `replacement`.
83102 public func replacing< S: Sequence , Replacement: Collection > (
84103 _ other: S ,
85104 with replacement: Replacement ,
@@ -91,7 +110,13 @@ extension RangeReplaceableCollection where Element: Equatable {
91110 subrange: startIndex..< endIndex,
92111 maxReplacements: maxReplacements)
93112 }
94-
113+
114+ /// Replaces all occurrences of a target sequence with a given collection
115+ /// - Parameters:
116+ /// - other: The sequence to replace.
117+ /// - replacement: The new elements to add to the collection.
118+ /// - maxReplacements: A number specifying how many occurrences of `other`
119+ /// to replace. Default is `Int.max`.
95120 public mutating func replace< S: Sequence , Replacement: Collection > (
96121 _ other: S ,
97122 with replacement: Replacement ,
@@ -108,7 +133,7 @@ extension RangeReplaceableCollection where Element: Equatable {
108133extension RangeReplaceableCollection
109134 where Self: BidirectionalCollection , Element: Comparable
110135{
111- public func replacing< S: Sequence , Replacement: Collection > (
136+ func replacing< S: Sequence , Replacement: Collection > (
112137 _ other: S ,
113138 with replacement: Replacement ,
114139 subrange: Range < Index > ,
@@ -121,7 +146,7 @@ extension RangeReplaceableCollection
121146 maxReplacements: maxReplacements)
122147 }
123148
124- public func replacing< S: Sequence , Replacement: Collection > (
149+ func replacing< S: Sequence , Replacement: Collection > (
125150 _ other: S ,
126151 with replacement: Replacement ,
127152 maxReplacements: Int = . max
@@ -133,7 +158,7 @@ extension RangeReplaceableCollection
133158 maxReplacements: maxReplacements)
134159 }
135160
136- public mutating func replace< S: Sequence , Replacement: Collection > (
161+ mutating func replace< S: Sequence , Replacement: Collection > (
137162 _ other: S ,
138163 with replacement: Replacement ,
139164 maxReplacements: Int = . max
@@ -149,6 +174,16 @@ extension RangeReplaceableCollection
149174// MARK: Regex algorithms
150175
151176extension RangeReplaceableCollection where SubSequence == Substring {
177+ /// Returns a new collection in which all occurrences of a sequence matching
178+ /// the given regex are replaced by another collection.
179+ /// - Parameters:
180+ /// - regex: A regex describing the sequence to replace.
181+ /// - replacement: The new elements to add to the collection.
182+ /// - subrange: The range in the collection in which to search for `regex`.
183+ /// - maxReplacements: A number specifying how many occurrences of the
184+ /// sequence matching `regex` to replace. Default is `Int.max`.
185+ /// - Returns: A new collection in which all occurrences of subsequence
186+ /// matching `regex` in `subrange` are replaced by `replacement`.
152187 public func replacing< R: RegexComponent , Replacement: Collection > (
153188 _ regex: R ,
154189 with replacement: Replacement ,
@@ -161,7 +196,16 @@ extension RangeReplaceableCollection where SubSequence == Substring {
161196 subrange: subrange,
162197 maxReplacements: maxReplacements)
163198 }
164-
199+
200+ /// Returns a new collection in which all occurrences of a sequence matching
201+ /// the given regex are replaced by another collection.
202+ /// - Parameters:
203+ /// - regex: A regex describing the sequence to replace.
204+ /// - replacement: The new elements to add to the collection.
205+ /// - maxReplacements: A number specifying how many occurrences of the
206+ /// sequence matching `regex` to replace. Default is `Int.max`.
207+ /// - Returns: A new collection in which all occurrences of subsequence
208+ /// matching `regex` are replaced by `replacement`.
165209 public func replacing< R: RegexComponent , Replacement: Collection > (
166210 _ regex: R ,
167211 with replacement: Replacement ,
@@ -173,7 +217,14 @@ extension RangeReplaceableCollection where SubSequence == Substring {
173217 subrange: startIndex..< endIndex,
174218 maxReplacements: maxReplacements)
175219 }
176-
220+
221+ /// Replaces all occurrences of the sequence matching the given regex with
222+ /// a given collection.
223+ /// - Parameters:
224+ /// - regex: A regex describing the sequence to replace.
225+ /// - replacement: The new elements to add to the collection.
226+ /// - maxReplacements: A number specifying how many occurrences of the
227+ /// sequence matching `regex` to replace. Default is `Int.max`.
177228 public mutating func replace< R: RegexComponent , Replacement: Collection > (
178229 _ regex: R ,
179230 with replacement: Replacement ,
0 commit comments