Skip to content

Commit 9277542

Browse files
committed
review accepted
1 parent 5b61082 commit 9277542

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Sources/Regex/AGMatchList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct AGMatchList: Sequence, Equatable {
1515
public let baseString: String
1616
private let list: [Element]
1717

18-
init(withBase base: String, matching matchList: [Element]) {
18+
init(base: String, matching matchList: [Element]) {
1919
baseString = base
2020
list = matchList
2121
}

Sources/Regex/AGRegex.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ public class AGRegex {
1919

2020
extension AGRegex {
2121

22-
public func getMatchList(_ str: String) -> AGMatchList {
22+
public func matchAll(_ str: String,
23+
options: NSRegularExpression.MatchingOptions = [] ) -> AGMatchList {
2324

2425
let matched = regex.matches(
2526
in: str,
26-
options: [],
27+
options: options,
2728
range: NSRange(location: 0, length: str.count))
2829

2930
let mapped: [AGMatch] = matched.map {
@@ -37,7 +38,7 @@ extension AGRegex {
3738
base: str, groups: group)
3839
}
3940

40-
return AGMatchList(withBase: str, matching: mapped)
41+
return AGMatchList(base: str, matching: mapped)
4142
}
4243

4344
public func sub(str: String, replace: String, count: Int = Int.max) -> String {

Tests/AGRegexTest.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class AGRegexTest: XCTestCase {
1616
let r = try! NSRegularExpression(pattern: "ai", options: [])
1717
let regex = AGRegex(r)
1818
let str = "The rain in Spain"
19-
let actual = regex.getMatchList(str)
20-
let expect = AGMatchList(withBase: str, matching: [
19+
let actual = regex.matchAll(str)
20+
let expect = AGMatchList(base: str, matching: [
2121
AGMatch(start: 5, end: 7, base: str, groups: ["ai"]),
2222
AGMatch(start: 14, end: 16, base: str, groups: ["ai"]),
2323
])
@@ -29,7 +29,7 @@ class AGRegexTest: XCTestCase {
2929
let r = try! NSRegularExpression(pattern: "ai", options: [])
3030
let regex = AGRegex(r)
3131
let str = "The rain in Spain"
32-
let actual = regex.getMatchList(str).first
32+
let actual = regex.matchAll(str).first
3333
let expect = AGMatch(start: 5, end: 7, base: str, groups: ["ai"])
3434
XCTAssertEqual(actual, expect)
3535
}
@@ -38,7 +38,7 @@ class AGRegexTest: XCTestCase {
3838
let r = try! NSRegularExpression(pattern: "ai", options: [])
3939
let regex = AGRegex(r)
4040
let str = "The rain in Spain"
41-
let actual = regex.getMatchList(str).last
41+
let actual = regex.matchAll(str).last
4242
let expect = AGMatch(start: 14, end: 16, base: str, groups: ["ai"])
4343
XCTAssertEqual(actual, expect)
4444
}
@@ -75,7 +75,7 @@ class AGRegexTest: XCTestCase {
7575
]
7676

7777
var testCount = 0
78-
for (i, m) in regex.getMatchList(str).enumerated() {
78+
for (i, m) in regex.matchAll(str).enumerated() {
7979
let actual = "\(m.group(2)) * \(m.group(1))"
8080
let expect = expects[i]
8181
XCTAssertEqual(actual, expect)

0 commit comments

Comments
 (0)