Skip to content

Commit a69c602

Browse files
authored
Merge pull request #166 from rxwei/match-dot-zero
Allow `.0` when `RegexMatch` has a non-tuple `Match`.
2 parents 52da66c + 21f85e6 commit a69c602

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Sources/_StringProcessing/RegexDSL/Match.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public struct RegexMatch<Match> {
1717
public subscript<T>(dynamicMember keyPath: KeyPath<Match, T>) -> T {
1818
match[keyPath: keyPath]
1919
}
20+
21+
// Allows `.0` when `Match` is not a tuple.
22+
@_disfavoredOverload
23+
public subscript(
24+
dynamicMember keyPath: KeyPath<(Match, _doNotUse: ()), Match>
25+
) -> Match {
26+
match
27+
}
2028
}
2129

2230
extension RegexProtocol {

Tests/RegexTests/RegexDSLTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class RegexDSLTests: XCTestCase {
6565
}
6666
}
6767

68+
func testMatchResultDotZeroWithoutCapture() throws {
69+
let match = try XCTUnwrap("aaa".match { oneOrMore { "a" } })
70+
XCTAssertEqual(match.0, "aaa")
71+
}
72+
6873
func testAlternation() throws {
6974
do {
7075
let regex = choiceOf {

0 commit comments

Comments
 (0)