12
12
// MARK: `CollectionSearcher` algorithms
13
13
14
14
extension RangeReplaceableCollection {
15
- public func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
15
+ func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
16
16
_ searcher: Searcher ,
17
17
with replacement: Replacement ,
18
18
subrange: Range < Index > ,
@@ -36,7 +36,7 @@ extension RangeReplaceableCollection {
36
36
return result
37
37
}
38
38
39
- public func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
39
+ func replacing< Searcher: CollectionSearcher , Replacement: Collection > (
40
40
_ searcher: Searcher ,
41
41
with replacement: Replacement ,
42
42
maxReplacements: Int = . max
@@ -50,7 +50,7 @@ extension RangeReplaceableCollection {
50
50
maxReplacements: maxReplacements)
51
51
}
52
52
53
- public mutating func replace<
53
+ mutating func replace<
54
54
Searcher: CollectionSearcher , Replacement: Collection
55
55
> (
56
56
_ searcher: Searcher ,
@@ -67,6 +67,16 @@ extension RangeReplaceableCollection {
67
67
// MARK: Fixed pattern algorithms
68
68
69
69
extension 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`.
70
80
public func replacing< S: Sequence , Replacement: Collection > (
71
81
_ other: S ,
72
82
with replacement: Replacement ,
@@ -79,7 +89,16 @@ extension RangeReplaceableCollection where Element: Equatable {
79
89
subrange: subrange,
80
90
maxReplacements: maxReplacements)
81
91
}
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`.
83
102
public func replacing< S: Sequence , Replacement: Collection > (
84
103
_ other: S ,
85
104
with replacement: Replacement ,
@@ -91,7 +110,13 @@ extension RangeReplaceableCollection where Element: Equatable {
91
110
subrange: startIndex..< endIndex,
92
111
maxReplacements: maxReplacements)
93
112
}
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`.
95
120
public mutating func replace< S: Sequence , Replacement: Collection > (
96
121
_ other: S ,
97
122
with replacement: Replacement ,
@@ -108,7 +133,7 @@ extension RangeReplaceableCollection where Element: Equatable {
108
133
extension RangeReplaceableCollection
109
134
where Self: BidirectionalCollection , Element: Comparable
110
135
{
111
- public func replacing< S: Sequence , Replacement: Collection > (
136
+ func replacing< S: Sequence , Replacement: Collection > (
112
137
_ other: S ,
113
138
with replacement: Replacement ,
114
139
subrange: Range < Index > ,
@@ -121,7 +146,7 @@ extension RangeReplaceableCollection
121
146
maxReplacements: maxReplacements)
122
147
}
123
148
124
- public func replacing< S: Sequence , Replacement: Collection > (
149
+ func replacing< S: Sequence , Replacement: Collection > (
125
150
_ other: S ,
126
151
with replacement: Replacement ,
127
152
maxReplacements: Int = . max
@@ -133,7 +158,7 @@ extension RangeReplaceableCollection
133
158
maxReplacements: maxReplacements)
134
159
}
135
160
136
- public mutating func replace< S: Sequence , Replacement: Collection > (
161
+ mutating func replace< S: Sequence , Replacement: Collection > (
137
162
_ other: S ,
138
163
with replacement: Replacement ,
139
164
maxReplacements: Int = . max
@@ -149,6 +174,16 @@ extension RangeReplaceableCollection
149
174
// MARK: Regex algorithms
150
175
151
176
extension 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`.
152
187
public func replacing< R: RegexComponent , Replacement: Collection > (
153
188
_ regex: R ,
154
189
with replacement: Replacement ,
@@ -161,7 +196,16 @@ extension RangeReplaceableCollection where SubSequence == Substring {
161
196
subrange: subrange,
162
197
maxReplacements: maxReplacements)
163
198
}
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`.
165
209
public func replacing< R: RegexComponent , Replacement: Collection > (
166
210
_ regex: R ,
167
211
with replacement: Replacement ,
@@ -173,7 +217,14 @@ extension RangeReplaceableCollection where SubSequence == Substring {
173
217
subrange: startIndex..< endIndex,
174
218
maxReplacements: maxReplacements)
175
219
}
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`.
177
228
public mutating func replace< R: RegexComponent , Replacement: Collection > (
178
229
_ regex: R ,
179
230
with replacement: Replacement ,
0 commit comments