Skip to content

Add wholeMatch and prefixMatch #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2022

Conversation

itingliu
Copy link
Contributor

Add the functions to string processing algorithms proposal and implement the
change.

Move the functions from String and SubString extensions to
BidirectionalCollection. Add tests for firstMatch, wholeMatch, and
prefixMatch that use a custom BidirectionalCollection type.

@milseman
Copy link
Member

I agree that if these are on String/Substring, they should instead be generic like the others. I weakly hold that they should exist, but I appreciate @natecook1000's perspective, especially if we have anchoring modifier APIs on Regex. Let's discuss this at the next sync up.

Add the functions to string processing algorithms proposal and
implement the change.

Move the functions from `String` and `SubString` extensions to
`BidirectionalCollection`. Add tests for `firstMatch`, `wholeMatch`,
and `prefixMatch` that use a custom `BidirectionalCollection` type.
@itingliu itingliu force-pushed the whole-match-prefix-match branch from 00c4021 to 4b5da35 Compare April 21, 2022 18:18
@itingliu
Copy link
Contributor Author

@swift-ci please test

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but potentially different parameter names for docs.

@@ -473,7 +484,7 @@ extension RangeReplaceableCollection where SubSequence == Substring {
/// - Returns: A new collection in which all occurrences of subsequence
/// matching `regex` in `subrange` are replaced by `replacement`.
public func replacing<R: RegexComponent, Replacement: Collection>(
_ regex: R,
_ r: R,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? It makes the doc comment above invalid

extension String {
extension BidirectionalCollection where SubSequence == Substring {
/// Match a regex in its entirety.
/// - Parameter r: The regex to match against.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... potential parameter names could be regex or pattern or regexComponent....

WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@milseman milseman merged commit 73a5ccf into swiftlang:main Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants