Skip to content

Commit a6f7b11

Browse files
committed
Underscore internal algorithms methods (swiftlang#414)
When working on overload resolution, it's trickier with these unnecessary name collisions. This includes a few symbols that might be public eventually, but we can de-underscore them at that point.
1 parent 64deaa7 commit a6f7b11

14 files changed

+135
-135
lines changed

Sources/_StringProcessing/Algorithms/Algorithms/Contains.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// MARK: `CollectionSearcher` algorithms
1313

1414
extension Collection {
15-
func contains<Searcher: CollectionSearcher>(
15+
func _contains<Searcher: CollectionSearcher>(
1616
_ searcher: Searcher
1717
) -> Bool where Searcher.Searched == Self {
18-
firstRange(of: searcher) != nil
18+
_firstRange(of: searcher) != nil
1919
}
2020
}
2121

@@ -36,7 +36,7 @@ extension Collection where Element: Equatable {
3636
}
3737

3838
extension BidirectionalCollection where Element: Comparable {
39-
func contains<C: Collection>(_ other: C) -> Bool
39+
func _contains<C: Collection>(_ other: C) -> Bool
4040
where C.Element == Element
4141
{
4242
if #available(SwiftStdlib 5.7, *) {
@@ -70,6 +70,6 @@ extension BidirectionalCollection where SubSequence == Substring {
7070
/// `false`.
7171
@available(SwiftStdlib 5.7, *)
7272
public func contains<R: RegexComponent>(_ regex: R) -> Bool {
73-
contains(RegexConsumer(regex))
73+
_contains(RegexConsumer(regex))
7474
}
7575
}

Sources/_StringProcessing/Algorithms/Algorithms/FirstRange.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// MARK: `CollectionSearcher` algorithms
1313

1414
extension Collection {
15-
func firstRange<S: CollectionSearcher>(
15+
func _firstRange<S: CollectionSearcher>(
1616
of searcher: S
1717
) -> Range<Index>? where S.Searched == Self {
1818
var state = searcher.state(for: self, in: startIndex..<endIndex)
@@ -21,7 +21,7 @@ extension Collection {
2121
}
2222

2323
extension BidirectionalCollection {
24-
func lastRange<S: BackwardCollectionSearcher>(
24+
func _lastRange<S: BackwardCollectionSearcher>(
2525
of searcher: S
2626
) -> Range<Index>? where S.BackwardSearched == Self {
2727
var state = searcher.backwardState(for: self, in: startIndex..<endIndex)
@@ -77,11 +77,11 @@ extension BidirectionalCollection where SubSequence == Substring {
7777
/// Returns `nil` if `regex` is not found.
7878
@available(SwiftStdlib 5.7, *)
7979
public func firstRange<R: RegexComponent>(of regex: R) -> Range<Index>? {
80-
firstRange(of: RegexConsumer(regex))
80+
_firstRange(of: RegexConsumer(regex))
8181
}
8282

8383
@available(SwiftStdlib 5.7, *)
84-
func lastRange<R: RegexComponent>(of regex: R) -> Range<Index>? {
85-
lastRange(of: RegexConsumer(regex))
84+
func _lastRange<R: RegexComponent>(of regex: R) -> Range<Index>? {
85+
_lastRange(of: RegexConsumer(regex))
8686
}
8787
}

Sources/_StringProcessing/Algorithms/Algorithms/Ranges.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ extension ReversedRangesCollection: Sequence {
157157
// MARK: `CollectionSearcher` algorithms
158158

159159
extension Collection {
160-
func ranges<S: CollectionSearcher>(
160+
func _ranges<S: CollectionSearcher>(
161161
of searcher: S
162162
) -> RangesCollection<S> where S.Searched == Self {
163163
RangesCollection(base: self, searcher: searcher)
164164
}
165165
}
166166

167167
extension BidirectionalCollection {
168-
func rangesFromBack<S: BackwardCollectionSearcher>(
168+
func _rangesFromBack<S: BackwardCollectionSearcher>(
169169
of searcher: S
170170
) -> ReversedRangesCollection<S> where S.BackwardSearched == Self {
171171
ReversedRangesCollection(base: self, searcher: searcher)
@@ -175,10 +175,10 @@ extension BidirectionalCollection {
175175
// MARK: Fixed pattern algorithms
176176

177177
extension Collection where Element: Equatable {
178-
func ranges<C: Collection>(
178+
func _ranges<C: Collection>(
179179
of other: C
180180
) -> RangesCollection<ZSearcher<Self>> where C.Element == Element {
181-
ranges(of: ZSearcher(pattern: Array(other), by: ==))
181+
_ranges(of: ZSearcher(pattern: Array(other), by: ==))
182182
}
183183

184184
// FIXME: Return `some Collection<Range<Index>>` for SE-0346
@@ -191,7 +191,7 @@ extension Collection where Element: Equatable {
191191
public func ranges<C: Collection>(
192192
of other: C
193193
) -> [Range<Index>] where C.Element == Element {
194-
ranges(of: ZSearcher(pattern: Array(other), by: ==)).map { $0 }
194+
Array(_ranges(of: other))
195195
}
196196
}
197197

@@ -207,12 +207,12 @@ extension BidirectionalCollection where Element: Equatable {
207207
}
208208

209209
extension BidirectionalCollection where Element: Comparable {
210-
func ranges<C: Collection>(
210+
func _ranges<C: Collection>(
211211
of other: C
212212
) -> RangesCollection<PatternOrEmpty<TwoWaySearcher<Self>>>
213213
where C.Element == Element
214214
{
215-
ranges(of: PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other))))
215+
_ranges(of: PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other))))
216216
}
217217

218218
// FIXME
@@ -231,17 +231,17 @@ extension BidirectionalCollection where Element: Comparable {
231231
extension BidirectionalCollection where SubSequence == Substring {
232232
@available(SwiftStdlib 5.7, *)
233233
@_disfavoredOverload
234-
func ranges<R: RegexComponent>(
234+
func _ranges<R: RegexComponent>(
235235
of regex: R
236236
) -> RangesCollection<RegexConsumer<R, Self>> {
237-
ranges(of: RegexConsumer(regex))
237+
_ranges(of: RegexConsumer(regex))
238238
}
239239

240240
@available(SwiftStdlib 5.7, *)
241-
func rangesFromBack<R: RegexComponent>(
241+
func _rangesFromBack<R: RegexComponent>(
242242
of regex: R
243243
) -> ReversedRangesCollection<RegexConsumer<R, Self>> {
244-
rangesFromBack(of: RegexConsumer(regex))
244+
_rangesFromBack(of: RegexConsumer(regex))
245245
}
246246

247247
// FIXME: Return `some Collection<Range<Index>>` for SE-0346
@@ -255,6 +255,6 @@ extension BidirectionalCollection where SubSequence == Substring {
255255
public func ranges<R: RegexComponent>(
256256
of regex: R
257257
) -> [Range<Index>] {
258-
Array(ranges(of: RegexConsumer(regex)))
258+
Array(_ranges(of: regex))
259259
}
260260
}

Sources/_StringProcessing/Algorithms/Algorithms/Replace.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// MARK: `CollectionSearcher` algorithms
1313

1414
extension RangeReplaceableCollection {
15-
func replacing<Searcher: CollectionSearcher, Replacement: Collection>(
15+
func _replacing<Searcher: CollectionSearcher, Replacement: Collection>(
1616
_ searcher: Searcher,
1717
with replacement: Replacement,
1818
subrange: Range<Index>,
@@ -26,7 +26,7 @@ extension RangeReplaceableCollection {
2626
var result = Self()
2727
result.append(contentsOf: self[..<index])
2828

29-
for range in self[subrange].ranges(of: searcher).prefix(maxReplacements) {
29+
for range in self[subrange]._ranges(of: searcher).prefix(maxReplacements) {
3030
result.append(contentsOf: self[index..<range.lowerBound])
3131
result.append(contentsOf: replacement)
3232
index = range.upperBound
@@ -36,28 +36,28 @@ extension RangeReplaceableCollection {
3636
return result
3737
}
3838

39-
func replacing<Searcher: CollectionSearcher, Replacement: Collection>(
39+
func _replacing<Searcher: CollectionSearcher, Replacement: Collection>(
4040
_ searcher: Searcher,
4141
with replacement: Replacement,
4242
maxReplacements: Int = .max
4343
) -> Self where Searcher.Searched == SubSequence,
4444
Replacement.Element == Element
4545
{
46-
replacing(
46+
_replacing(
4747
searcher,
4848
with: replacement,
4949
subrange: startIndex..<endIndex,
5050
maxReplacements: maxReplacements)
5151
}
5252

53-
mutating func replace<
53+
mutating func _replace<
5454
Searcher: CollectionSearcher, Replacement: Collection
5555
>(
5656
_ searcher: Searcher,
5757
with replacement: Replacement,
5858
maxReplacements: Int = .max
5959
) where Searcher.Searched == SubSequence, Replacement.Element == Element {
60-
self = replacing(
60+
self = _replacing(
6161
searcher,
6262
with: replacement,
6363
maxReplacements: maxReplacements)
@@ -84,7 +84,7 @@ extension RangeReplaceableCollection where Element: Equatable {
8484
subrange: Range<Index>,
8585
maxReplacements: Int = .max
8686
) -> Self where C.Element == Element, Replacement.Element == Element {
87-
replacing(
87+
_replacing(
8888
ZSearcher(pattern: Array(other), by: ==),
8989
with: replacement,
9090
subrange: subrange,
@@ -136,37 +136,37 @@ extension RangeReplaceableCollection where Element: Equatable {
136136
extension RangeReplaceableCollection
137137
where Self: BidirectionalCollection, Element: Comparable
138138
{
139-
func replacing<C: Collection, Replacement: Collection>(
139+
func _replacing<C: Collection, Replacement: Collection>(
140140
_ other: C,
141141
with replacement: Replacement,
142142
subrange: Range<Index>,
143143
maxReplacements: Int = .max
144144
) -> Self where C.Element == Element, Replacement.Element == Element {
145-
replacing(
145+
_replacing(
146146
PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other))),
147147
with: replacement,
148148
subrange: subrange,
149149
maxReplacements: maxReplacements)
150150
}
151151

152-
func replacing<C: Collection, Replacement: Collection>(
152+
func _replacing<C: Collection, Replacement: Collection>(
153153
_ other: C,
154154
with replacement: Replacement,
155155
maxReplacements: Int = .max
156156
) -> Self where C.Element == Element, Replacement.Element == Element {
157-
replacing(
157+
_replacing(
158158
other,
159159
with: replacement,
160160
subrange: startIndex..<endIndex,
161161
maxReplacements: maxReplacements)
162162
}
163163

164-
mutating func replace<C: Collection, Replacement: Collection>(
164+
mutating func _replace<C: Collection, Replacement: Collection>(
165165
_ other: C,
166166
with replacement: Replacement,
167167
maxReplacements: Int = .max
168168
) where C.Element == Element, Replacement.Element == Element {
169-
self = replacing(
169+
self = _replacing(
170170
other,
171171
with: replacement,
172172
subrange: startIndex..<endIndex,
@@ -194,7 +194,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
194194
subrange: Range<Index>,
195195
maxReplacements: Int = .max
196196
) -> Self where Replacement.Element == Element {
197-
replacing(
197+
_replacing(
198198
RegexConsumer(regex),
199199
with: replacement,
200200
subrange: subrange,

Sources/_StringProcessing/Algorithms/Algorithms/Split.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct SplitCollection<Searcher: CollectionSearcher> {
3434
maxSplits: Int,
3535
omittingEmptySubsequences: Bool)
3636
{
37-
self.ranges = base.ranges(of: searcher)
37+
self.ranges = base._ranges(of: searcher)
3838
self.maxSplits = maxSplits
3939
self.omittingEmptySubsequences = omittingEmptySubsequences
4040
}
@@ -183,7 +183,7 @@ struct ReversedSplitCollection<Searcher: BackwardCollectionSearcher> {
183183
}
184184

185185
init(base: Base, searcher: Searcher) {
186-
self.ranges = base.rangesFromBack(of: searcher)
186+
self.ranges = base._rangesFromBack(of: searcher)
187187
}
188188
}
189189

Sources/_StringProcessing/Algorithms/Algorithms/StartsWith.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
// MARK: `CollectionConsumer` algorithms
1313

1414
extension Collection {
15-
func starts<C: CollectionConsumer>(with consumer: C) -> Bool
15+
func _starts<C: CollectionConsumer>(with consumer: C) -> Bool
1616
where C.Consumed == SubSequence
1717
{
1818
consumer.consuming(self[...]) != nil
1919
}
2020
}
2121

2222
extension BidirectionalCollection {
23-
func ends<C: BidirectionalCollectionConsumer>(with consumer: C) -> Bool
23+
func _ends<C: BidirectionalCollectionConsumer>(with consumer: C) -> Bool
2424
where C.Consumed == SubSequence
2525
{
2626
consumer.consumingBack(self[...]) != nil
@@ -30,18 +30,18 @@ extension BidirectionalCollection {
3030
// MARK: Fixed pattern algorithms
3131

3232
extension Collection where Element: Equatable {
33-
func starts<C: Collection>(with prefix: C) -> Bool
33+
func _starts<C: Collection>(with prefix: C) -> Bool
3434
where C.Element == Element
3535
{
36-
starts(with: FixedPatternConsumer(pattern: prefix))
36+
_starts(with: FixedPatternConsumer(pattern: prefix))
3737
}
3838
}
3939

4040
extension BidirectionalCollection where Element: Equatable {
41-
func ends<C: BidirectionalCollection>(with suffix: C) -> Bool
41+
func _ends<C: BidirectionalCollection>(with suffix: C) -> Bool
4242
where C.Element == Element
4343
{
44-
ends(with: FixedPatternConsumer(pattern: suffix))
44+
_ends(with: FixedPatternConsumer(pattern: suffix))
4545
}
4646
}
4747

@@ -56,10 +56,10 @@ extension BidirectionalCollection where SubSequence == Substring {
5656
/// - Returns: `true` if the initial elements of the sequence matches the
5757
/// beginning of `regex`; otherwise, `false`.
5858
public func starts<R: RegexComponent>(with regex: R) -> Bool {
59-
starts(with: RegexConsumer(regex))
59+
_starts(with: RegexConsumer(regex))
6060
}
6161

62-
func ends<R: RegexComponent>(with regex: R) -> Bool {
63-
ends(with: RegexConsumer(regex))
62+
func _ends<R: RegexComponent>(with regex: R) -> Bool {
63+
_ends(with: RegexConsumer(regex))
6464
}
6565
}

0 commit comments

Comments
 (0)