From 8bd9a4f45a04a3b77853111874fc060764cf2c5a Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Fri, 13 May 2022 17:17:16 -0500 Subject: [PATCH] Underscore internal algorithms methods 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. --- .../Algorithms/Algorithms/Contains.swift | 8 +- .../Algorithms/Algorithms/FirstRange.swift | 10 +- .../Algorithms/Algorithms/Ranges.swift | 24 ++-- .../Algorithms/Algorithms/Replace.swift | 28 ++-- .../Algorithms/Algorithms/Split.swift | 4 +- .../Algorithms/Algorithms/StartsWith.swift | 18 +-- .../Algorithms/Algorithms/Trim.swift | 124 +++++++++--------- .../Algorithms/Matching/FirstMatch.swift | 4 +- .../Algorithms/Matching/MatchReplace.swift | 24 ++-- .../Algorithms/Matching/Matches.swift | 12 +- .../Algorithms/Searchers/TwoWaySearcher.swift | 2 +- .../_StringProcessing/ConsumerInterface.swift | 2 +- .../_StringProcessing/PrintAsPattern.swift | 2 +- .../RegexTests/AlgorithmsInternalsTests.swift | 8 +- 14 files changed, 135 insertions(+), 135 deletions(-) diff --git a/Sources/_StringProcessing/Algorithms/Algorithms/Contains.swift b/Sources/_StringProcessing/Algorithms/Algorithms/Contains.swift index 2a1ef72a2..bb86f4676 100644 --- a/Sources/_StringProcessing/Algorithms/Algorithms/Contains.swift +++ b/Sources/_StringProcessing/Algorithms/Algorithms/Contains.swift @@ -12,10 +12,10 @@ // MARK: `CollectionSearcher` algorithms extension Collection { - func contains( + func _contains( _ searcher: Searcher ) -> Bool where Searcher.Searched == Self { - firstRange(of: searcher) != nil + _firstRange(of: searcher) != nil } } @@ -36,7 +36,7 @@ extension Collection where Element: Equatable { } extension BidirectionalCollection where Element: Comparable { - func contains(_ other: C) -> Bool + func _contains(_ other: C) -> Bool where C.Element == Element { if #available(SwiftStdlib 5.7, *) { @@ -70,6 +70,6 @@ extension BidirectionalCollection where SubSequence == Substring { /// `false`. @available(SwiftStdlib 5.7, *) public func contains(_ regex: R) -> Bool { - contains(RegexConsumer(regex)) + _contains(RegexConsumer(regex)) } } diff --git a/Sources/_StringProcessing/Algorithms/Algorithms/FirstRange.swift b/Sources/_StringProcessing/Algorithms/Algorithms/FirstRange.swift index 42703827e..ad5c535d4 100644 --- a/Sources/_StringProcessing/Algorithms/Algorithms/FirstRange.swift +++ b/Sources/_StringProcessing/Algorithms/Algorithms/FirstRange.swift @@ -12,7 +12,7 @@ // MARK: `CollectionSearcher` algorithms extension Collection { - func firstRange( + func _firstRange( of searcher: S ) -> Range? where S.Searched == Self { var state = searcher.state(for: self, in: startIndex..( + func _lastRange( of searcher: S ) -> Range? where S.BackwardSearched == Self { var state = searcher.backwardState(for: self, in: startIndex..(of regex: R) -> Range? { - firstRange(of: RegexConsumer(regex)) + _firstRange(of: RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - func lastRange(of regex: R) -> Range? { - lastRange(of: RegexConsumer(regex)) + func _lastRange(of regex: R) -> Range? { + _lastRange(of: RegexConsumer(regex)) } } diff --git a/Sources/_StringProcessing/Algorithms/Algorithms/Ranges.swift b/Sources/_StringProcessing/Algorithms/Algorithms/Ranges.swift index 33a9748ac..9f3c50c7c 100644 --- a/Sources/_StringProcessing/Algorithms/Algorithms/Ranges.swift +++ b/Sources/_StringProcessing/Algorithms/Algorithms/Ranges.swift @@ -157,7 +157,7 @@ extension ReversedRangesCollection: Sequence { // MARK: `CollectionSearcher` algorithms extension Collection { - func ranges( + func _ranges( of searcher: S ) -> RangesCollection where S.Searched == Self { RangesCollection(base: self, searcher: searcher) @@ -165,7 +165,7 @@ extension Collection { } extension BidirectionalCollection { - func rangesFromBack( + func _rangesFromBack( of searcher: S ) -> ReversedRangesCollection where S.BackwardSearched == Self { ReversedRangesCollection(base: self, searcher: searcher) @@ -175,10 +175,10 @@ extension BidirectionalCollection { // MARK: Fixed pattern algorithms extension Collection where Element: Equatable { - func ranges( + func _ranges( of other: C ) -> RangesCollection> where C.Element == Element { - ranges(of: ZSearcher(pattern: Array(other), by: ==)) + _ranges(of: ZSearcher(pattern: Array(other), by: ==)) } // FIXME: Return `some Collection>` for SE-0346 @@ -191,7 +191,7 @@ extension Collection where Element: Equatable { public func ranges( of other: C ) -> [Range] where C.Element == Element { - ranges(of: ZSearcher(pattern: Array(other), by: ==)).map { $0 } + Array(_ranges(of: other)) } } @@ -207,12 +207,12 @@ extension BidirectionalCollection where Element: Equatable { } extension BidirectionalCollection where Element: Comparable { - func ranges( + func _ranges( of other: C ) -> RangesCollection>> where C.Element == Element { - ranges(of: PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other)))) + _ranges(of: PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other)))) } // FIXME @@ -231,17 +231,17 @@ extension BidirectionalCollection where Element: Comparable { extension BidirectionalCollection where SubSequence == Substring { @available(SwiftStdlib 5.7, *) @_disfavoredOverload - func ranges( + func _ranges( of regex: R ) -> RangesCollection> { - ranges(of: RegexConsumer(regex)) + _ranges(of: RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - func rangesFromBack( + func _rangesFromBack( of regex: R ) -> ReversedRangesCollection> { - rangesFromBack(of: RegexConsumer(regex)) + _rangesFromBack(of: RegexConsumer(regex)) } // FIXME: Return `some Collection>` for SE-0346 @@ -255,6 +255,6 @@ extension BidirectionalCollection where SubSequence == Substring { public func ranges( of regex: R ) -> [Range] { - Array(ranges(of: RegexConsumer(regex))) + Array(_ranges(of: regex)) } } diff --git a/Sources/_StringProcessing/Algorithms/Algorithms/Replace.swift b/Sources/_StringProcessing/Algorithms/Algorithms/Replace.swift index 217fb90d6..daf726fe7 100644 --- a/Sources/_StringProcessing/Algorithms/Algorithms/Replace.swift +++ b/Sources/_StringProcessing/Algorithms/Algorithms/Replace.swift @@ -12,7 +12,7 @@ // MARK: `CollectionSearcher` algorithms extension RangeReplaceableCollection { - func replacing( + func _replacing( _ searcher: Searcher, with replacement: Replacement, subrange: Range, @@ -26,7 +26,7 @@ extension RangeReplaceableCollection { var result = Self() result.append(contentsOf: self[..( + func _replacing( _ searcher: Searcher, with replacement: Replacement, maxReplacements: Int = .max ) -> Self where Searcher.Searched == SubSequence, Replacement.Element == Element { - replacing( + _replacing( searcher, with: replacement, subrange: startIndex..( _ searcher: Searcher, with replacement: Replacement, maxReplacements: Int = .max ) where Searcher.Searched == SubSequence, Replacement.Element == Element { - self = replacing( + self = _replacing( searcher, with: replacement, maxReplacements: maxReplacements) @@ -84,7 +84,7 @@ extension RangeReplaceableCollection where Element: Equatable { subrange: Range, maxReplacements: Int = .max ) -> Self where C.Element == Element, Replacement.Element == Element { - replacing( + _replacing( ZSearcher(pattern: Array(other), by: ==), with: replacement, subrange: subrange, @@ -136,37 +136,37 @@ extension RangeReplaceableCollection where Element: Equatable { extension RangeReplaceableCollection where Self: BidirectionalCollection, Element: Comparable { - func replacing( + func _replacing( _ other: C, with replacement: Replacement, subrange: Range, maxReplacements: Int = .max ) -> Self where C.Element == Element, Replacement.Element == Element { - replacing( + _replacing( PatternOrEmpty(searcher: TwoWaySearcher(pattern: Array(other))), with: replacement, subrange: subrange, maxReplacements: maxReplacements) } - func replacing( + func _replacing( _ other: C, with replacement: Replacement, maxReplacements: Int = .max ) -> Self where C.Element == Element, Replacement.Element == Element { - replacing( + _replacing( other, with: replacement, subrange: startIndex..( + mutating func _replace( _ other: C, with replacement: Replacement, maxReplacements: Int = .max ) where C.Element == Element, Replacement.Element == Element { - self = replacing( + self = _replacing( other, with: replacement, subrange: startIndex.., maxReplacements: Int = .max ) -> Self where Replacement.Element == Element { - replacing( + _replacing( RegexConsumer(regex), with: replacement, subrange: subrange, diff --git a/Sources/_StringProcessing/Algorithms/Algorithms/Split.swift b/Sources/_StringProcessing/Algorithms/Algorithms/Split.swift index ab465c382..412197557 100644 --- a/Sources/_StringProcessing/Algorithms/Algorithms/Split.swift +++ b/Sources/_StringProcessing/Algorithms/Algorithms/Split.swift @@ -34,7 +34,7 @@ struct SplitCollection { maxSplits: Int, omittingEmptySubsequences: Bool) { - self.ranges = base.ranges(of: searcher) + self.ranges = base._ranges(of: searcher) self.maxSplits = maxSplits self.omittingEmptySubsequences = omittingEmptySubsequences } @@ -183,7 +183,7 @@ struct ReversedSplitCollection { } init(base: Base, searcher: Searcher) { - self.ranges = base.rangesFromBack(of: searcher) + self.ranges = base._rangesFromBack(of: searcher) } } diff --git a/Sources/_StringProcessing/Algorithms/Algorithms/StartsWith.swift b/Sources/_StringProcessing/Algorithms/Algorithms/StartsWith.swift index 2f45a734b..c8aaf9126 100644 --- a/Sources/_StringProcessing/Algorithms/Algorithms/StartsWith.swift +++ b/Sources/_StringProcessing/Algorithms/Algorithms/StartsWith.swift @@ -12,7 +12,7 @@ // MARK: `CollectionConsumer` algorithms extension Collection { - func starts(with consumer: C) -> Bool + func _starts(with consumer: C) -> Bool where C.Consumed == SubSequence { consumer.consuming(self[...]) != nil @@ -20,7 +20,7 @@ extension Collection { } extension BidirectionalCollection { - func ends(with consumer: C) -> Bool + func _ends(with consumer: C) -> Bool where C.Consumed == SubSequence { consumer.consumingBack(self[...]) != nil @@ -30,18 +30,18 @@ extension BidirectionalCollection { // MARK: Fixed pattern algorithms extension Collection where Element: Equatable { - func starts(with prefix: C) -> Bool + func _starts(with prefix: C) -> Bool where C.Element == Element { - starts(with: FixedPatternConsumer(pattern: prefix)) + _starts(with: FixedPatternConsumer(pattern: prefix)) } } extension BidirectionalCollection where Element: Equatable { - func ends(with suffix: C) -> Bool + func _ends(with suffix: C) -> Bool where C.Element == Element { - ends(with: FixedPatternConsumer(pattern: suffix)) + _ends(with: FixedPatternConsumer(pattern: suffix)) } } @@ -56,10 +56,10 @@ extension BidirectionalCollection where SubSequence == Substring { /// - Returns: `true` if the initial elements of the sequence matches the /// beginning of `regex`; otherwise, `false`. public func starts(with regex: R) -> Bool { - starts(with: RegexConsumer(regex)) + _starts(with: RegexConsumer(regex)) } - func ends(with regex: R) -> Bool { - ends(with: RegexConsumer(regex)) + func _ends(with regex: R) -> Bool { + _ends(with: RegexConsumer(regex)) } } diff --git a/Sources/_StringProcessing/Algorithms/Algorithms/Trim.swift b/Sources/_StringProcessing/Algorithms/Algorithms/Trim.swift index 7411236da..2e955507b 100644 --- a/Sources/_StringProcessing/Algorithms/Algorithms/Trim.swift +++ b/Sources/_StringProcessing/Algorithms/Algorithms/Trim.swift @@ -12,7 +12,7 @@ // MARK: `CollectionConsumer` algorithms extension Collection { - func trimmingPrefix( + func _trimmingPrefix( _ consumer: Consumer ) -> SubSequence where Consumer.Consumed == Self { let start = consumer.consuming(self) ?? startIndex @@ -21,7 +21,7 @@ extension Collection { } extension Collection where SubSequence == Self { - mutating func trimPrefix( + mutating func _trimPrefix( _ consumer: Consumer ) where Consumer.Consumed == Self { _ = consumer.consume(&self) @@ -32,7 +32,7 @@ extension RangeReplaceableCollection { // NOTE: Disfavored because the `Collection with SubSequence == Self` overload // should be preferred whenever both are available @_disfavoredOverload - mutating func trimPrefix( + mutating func _trimPrefix( _ consumer: Consumer ) where Consumer.Consumed == Self { if let start = consumer.consuming(self) { @@ -42,7 +42,7 @@ extension RangeReplaceableCollection { } extension BidirectionalCollection { - func trimmingSuffix( + func _trimmingSuffix( _ consumer: Consumer ) -> SubSequence where Consumer.Consumed == Self @@ -51,7 +51,7 @@ extension BidirectionalCollection { return self[..( + func _trimming( _ consumer: Consumer ) -> SubSequence where Consumer.Consumed == Self { // NOTE: Might give different results than trimming the suffix before @@ -64,24 +64,24 @@ extension BidirectionalCollection { } extension BidirectionalCollection where SubSequence == Self { - mutating func trimSuffix( + mutating func _trimSuffix( _ consumer: Consumer ) where Consumer.Consumed == SubSequence { _ = consumer.consumeBack(&self) } - mutating func trim( + mutating func _trim( _ consumer: Consumer ) where Consumer.Consumed == Self { - trimPrefix(consumer) - trimSuffix(consumer) + _trimPrefix(consumer) + _trimSuffix(consumer) } } extension RangeReplaceableCollection where Self: BidirectionalCollection { @_disfavoredOverload - mutating func trimSuffix( + mutating func _trimSuffix( _ consumer: Consumer ) where Consumer.Consumed == Self { @@ -91,11 +91,11 @@ extension RangeReplaceableCollection where Self: BidirectionalCollection { } @_disfavoredOverload - mutating func trim( + mutating func _trim( _ consumer: Consumer ) where Consumer.Consumed == Self { - trimSuffix(consumer) - trimPrefix(consumer) + _trimSuffix(consumer) + _trimPrefix(consumer) } } @@ -137,49 +137,49 @@ extension RangeReplaceableCollection { } extension BidirectionalCollection { - func trimmingSuffix( + func _trimmingSuffix( while predicate: @escaping (Element) -> Bool ) -> SubSequence { - trimmingSuffix(ManyConsumer(base: PredicateConsumer(predicate: predicate))) + _trimmingSuffix(ManyConsumer(base: PredicateConsumer(predicate: predicate))) } - func trimming( + func _trimming( while predicate: @escaping (Element) -> Bool ) -> SubSequence { - trimming(ManyConsumer(base: PredicateConsumer(predicate: predicate))) + _trimming(ManyConsumer(base: PredicateConsumer(predicate: predicate))) } } extension BidirectionalCollection where SubSequence == Self { - mutating func trimSuffix( + mutating func _trimSuffix( while predicate: @escaping (Element) -> Bool ) { - trimSuffix(ManyConsumer( + _trimSuffix(ManyConsumer( base: PredicateConsumer(predicate: predicate))) } - mutating func trim(while predicate: @escaping (Element) -> Bool) { + mutating func _trim(while predicate: @escaping (Element) -> Bool) { let consumer = ManyConsumer( base: PredicateConsumer(predicate: predicate)) - trimPrefix(consumer) - trimSuffix(consumer) + _trimPrefix(consumer) + _trimSuffix(consumer) } } extension RangeReplaceableCollection where Self: BidirectionalCollection { @_disfavoredOverload - mutating func trimSuffix( + mutating func _trimSuffix( while predicate: @escaping (Element) -> Bool ) { - trimSuffix(ManyConsumer(base: PredicateConsumer(predicate: predicate))) + _trimSuffix(ManyConsumer(base: PredicateConsumer(predicate: predicate))) } @_disfavoredOverload - mutating func trim(while predicate: @escaping (Element) -> Bool) { + mutating func _trim(while predicate: @escaping (Element) -> Bool) { let consumer = ManyConsumer( base: PredicateConsumer(predicate: predicate)) - trimPrefix(consumer) - trimSuffix(consumer) + _trimPrefix(consumer) + _trimSuffix(consumer) } } @@ -197,7 +197,7 @@ extension Collection where Element: Equatable { public func trimmingPrefix( _ prefix: Prefix ) -> SubSequence where Prefix.Element == Element { - trimmingPrefix(FixedPatternConsumer(pattern: prefix)) + _trimmingPrefix(FixedPatternConsumer(pattern: prefix)) } } @@ -211,7 +211,7 @@ extension Collection where SubSequence == Self, Element: Equatable { public mutating func trimPrefix( _ prefix: Prefix ) where Prefix.Element == Element { - trimPrefix(FixedPatternConsumer(pattern: prefix)) + _trimPrefix(FixedPatternConsumer(pattern: prefix)) } } @@ -226,39 +226,39 @@ extension RangeReplaceableCollection where Element: Equatable { public mutating func trimPrefix( _ prefix: Prefix ) where Prefix.Element == Element { - trimPrefix(FixedPatternConsumer(pattern: prefix)) + _trimPrefix(FixedPatternConsumer(pattern: prefix)) } } extension BidirectionalCollection where Element: Equatable { - func trimmingSuffix( + func _trimmingSuffix( _ suffix: Suffix ) -> SubSequence where Suffix.Element == Element { - trimmingSuffix(FixedPatternConsumer(pattern: suffix)) + _trimmingSuffix(FixedPatternConsumer(pattern: suffix)) } - func trimming( + func _trimming( _ pattern: Pattern ) -> SubSequence where Pattern.Element == Element { - trimming(FixedPatternConsumer(pattern: pattern)) + _trimming(FixedPatternConsumer(pattern: pattern)) } } extension BidirectionalCollection where SubSequence == Self, Element: Equatable { - mutating func trimSuffix( + mutating func _trimSuffix( _ suffix: Suffix ) where Suffix.Element == Element { - trimSuffix(FixedPatternConsumer(pattern: suffix)) + _trimSuffix(FixedPatternConsumer(pattern: suffix)) } - mutating func trim( + mutating func _trim( _ pattern: Pattern ) where Pattern.Element == Element { let consumer = FixedPatternConsumer(pattern: pattern) - trimPrefix(consumer) - trimSuffix(consumer) + _trimPrefix(consumer) + _trimSuffix(consumer) } } @@ -266,19 +266,19 @@ extension RangeReplaceableCollection where Self: BidirectionalCollection, Element: Equatable { @_disfavoredOverload - mutating func trimSuffix( + mutating func _trimSuffix( _ prefix: Suffix ) where Suffix.Element == Element { - trimSuffix(FixedPatternConsumer(pattern: prefix)) + _trimSuffix(FixedPatternConsumer(pattern: prefix)) } @_disfavoredOverload - mutating func trim( + mutating func _trim( _ pattern: Pattern ) where Pattern.Element == Element { let consumer = FixedPatternConsumer(pattern: pattern) - trimPrefix(consumer) - trimSuffix(consumer) + _trimPrefix(consumer) + _trimSuffix(consumer) } } @@ -292,17 +292,17 @@ extension BidirectionalCollection where SubSequence == Substring { /// `prefix` from the start. @available(SwiftStdlib 5.7, *) public func trimmingPrefix(_ regex: R) -> SubSequence { - trimmingPrefix(RegexConsumer(regex)) + _trimmingPrefix(RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - func trimmingSuffix(_ regex: R) -> SubSequence { - trimmingSuffix(RegexConsumer(regex)) + func _trimmingSuffix(_ regex: R) -> SubSequence { + _trimmingSuffix(RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - func trimming(_ regex: R) -> SubSequence { - trimming(RegexConsumer(regex)) + func _trimming(_ regex: R) -> SubSequence { + _trimming(RegexConsumer(regex)) } } @@ -313,37 +313,37 @@ extension RangeReplaceableCollection /// - Parameter regex: The regex to remove from this collection. @available(SwiftStdlib 5.7, *) public mutating func trimPrefix(_ regex: R) { - trimPrefix(RegexConsumer(regex)) + _trimPrefix(RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - mutating func trimSuffix(_ regex: R) { - trimSuffix(RegexConsumer(regex)) + mutating func _trimSuffix(_ regex: R) { + _trimSuffix(RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - mutating func trim(_ regex: R) { + mutating func _trim(_ regex: R) { let consumer = RegexConsumer(regex) - trimPrefix(consumer) - trimSuffix(consumer) + _trimPrefix(consumer) + _trimSuffix(consumer) } } extension Substring { @available(SwiftStdlib 5.7, *) - mutating func trimPrefix(_ regex: R) { - trimPrefix(RegexConsumer(regex)) + mutating func _trimPrefix(_ regex: R) { + _trimPrefix(RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - mutating func trimSuffix(_ regex: R) { - trimSuffix(RegexConsumer(regex)) + mutating func _trimSuffix(_ regex: R) { + _trimSuffix(RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - mutating func trim(_ regex: R) { + mutating func _trim(_ regex: R) { let consumer = RegexConsumer(regex) - trimPrefix(consumer) - trimSuffix(consumer) + _trimPrefix(consumer) + _trimSuffix(consumer) } } diff --git a/Sources/_StringProcessing/Algorithms/Matching/FirstMatch.swift b/Sources/_StringProcessing/Algorithms/Matching/FirstMatch.swift index 4342391af..2b6dd1704 100644 --- a/Sources/_StringProcessing/Algorithms/Matching/FirstMatch.swift +++ b/Sources/_StringProcessing/Algorithms/Matching/FirstMatch.swift @@ -12,7 +12,7 @@ // MARK: `CollectionSearcher` algorithms extension Collection { - func firstMatch( + func _firstMatch( of searcher: S ) -> _MatchResult? where S.Searched == Self { var state = searcher.state(for: self, in: startIndex..( of regex: R ) -> _MatchResult>? { - firstMatch(of: RegexConsumer(regex)) + _firstMatch(of: RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) diff --git a/Sources/_StringProcessing/Algorithms/Matching/MatchReplace.swift b/Sources/_StringProcessing/Algorithms/Matching/MatchReplace.swift index 206d68554..38224e30f 100644 --- a/Sources/_StringProcessing/Algorithms/Matching/MatchReplace.swift +++ b/Sources/_StringProcessing/Algorithms/Matching/MatchReplace.swift @@ -12,7 +12,7 @@ // MARK: `MatchingCollectionSearcher` algorithms extension RangeReplaceableCollection { - func replacing< + func _replacing< Searcher: MatchingCollectionSearcher, Replacement: Collection >( _ searcher: Searcher, @@ -28,7 +28,7 @@ extension RangeReplaceableCollection { var result = Self() result.append(contentsOf: self[..( _ searcher: Searcher, @@ -49,14 +49,14 @@ extension RangeReplaceableCollection { ) rethrows -> Self where Searcher.Searched == SubSequence, Replacement.Element == Element { - try replacing( + try _replacing( searcher, with: replacement, subrange: startIndex..( _ searcher: Searcher, @@ -65,7 +65,7 @@ extension RangeReplaceableCollection { ) rethrows where Searcher.Searched == SubSequence, Replacement.Element == Element { - self = try replacing( + self = try _replacing( searcher, with: replacement, maxReplacements: maxReplacements) @@ -76,13 +76,13 @@ extension RangeReplaceableCollection { extension RangeReplaceableCollection where SubSequence == Substring { @available(SwiftStdlib 5.7, *) - func replacing( + func _replacing( _ regex: R, with replacement: (_MatchResult>) throws -> Replacement, subrange: Range, maxReplacements: Int = .max ) rethrows -> Self where Replacement.Element == Element { - try replacing( + try _replacing( RegexConsumer(regex), with: replacement, subrange: subrange, @@ -90,12 +90,12 @@ extension RangeReplaceableCollection where SubSequence == Substring { } @available(SwiftStdlib 5.7, *) - func replacing( + func _replacing( _ regex: R, with replacement: (_MatchResult>) throws -> Replacement, maxReplacements: Int = .max ) rethrows -> Self where Replacement.Element == Element { - try replacing( + try _replacing( regex, with: replacement, subrange: startIndex..( + mutating func _replace( _ regex: R, with replacement: (_MatchResult>) throws -> Replacement, maxReplacements: Int = .max ) rethrows where Replacement.Element == Element { - self = try replacing( + self = try _replacing( regex, with: replacement, maxReplacements: maxReplacements) diff --git a/Sources/_StringProcessing/Algorithms/Matching/Matches.swift b/Sources/_StringProcessing/Algorithms/Matching/Matches.swift index f038616fe..3987e8f97 100644 --- a/Sources/_StringProcessing/Algorithms/Matching/Matches.swift +++ b/Sources/_StringProcessing/Algorithms/Matching/Matches.swift @@ -166,7 +166,7 @@ extension ReversedMatchesCollection: Sequence { // MARK: `CollectionSearcher` algorithms extension Collection { - func matches( + func _matches( of searcher: S ) -> MatchesCollection where S.Searched == Self { MatchesCollection(base: self, searcher: searcher) @@ -174,7 +174,7 @@ extension Collection { } extension BidirectionalCollection { - func matchesFromBack( + func _matchesFromBack( of searcher: S ) -> ReversedMatchesCollection where S.BackwardSearched == Self { ReversedMatchesCollection(base: self, searcher: searcher) @@ -186,17 +186,17 @@ extension BidirectionalCollection { extension BidirectionalCollection where SubSequence == Substring { @available(SwiftStdlib 5.7, *) @_disfavoredOverload - func matches( + func _matches( of regex: R ) -> MatchesCollection> { - matches(of: RegexConsumer(regex)) + _matches(of: RegexConsumer(regex)) } @available(SwiftStdlib 5.7, *) - func matchesFromBack( + func _matchesFromBack( of regex: R ) -> ReversedMatchesCollection> { - matchesFromBack(of: RegexConsumer(regex)) + _matchesFromBack(of: RegexConsumer(regex)) } // FIXME: Return `some Collection.Match> for SE-0346 diff --git a/Sources/_StringProcessing/Algorithms/Searchers/TwoWaySearcher.swift b/Sources/_StringProcessing/Algorithms/Searchers/TwoWaySearcher.swift index ae613cfd7..837493a30 100644 --- a/Sources/_StringProcessing/Algorithms/Searchers/TwoWaySearcher.swift +++ b/Sources/_StringProcessing/Algorithms/Searchers/TwoWaySearcher.swift @@ -24,7 +24,7 @@ struct TwoWaySearcher let (criticalIndex, periodOfSecondPart) = pattern._criticalFactorization(<) let periodIsExact = pattern[criticalIndex...] .prefix(periodOfSecondPart) - .ends(with: pattern[..