Skip to content

Commit 1e1d29a

Browse files
committed
Migrate TicTacToeMove to regex literals
1 parent e7c58f0 commit 1e1d29a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: Sources/D2Commands/game/tictactoe/TicTacToeMove.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Utils
22

3-
fileprivate let argsRegex = try! LegacyRegex(from: "(\\S+)\\s+(\\S+)")
3+
fileprivate let argsRegex = #/(\\S+)\\s+(\\S+)/#
44

55
public struct TicTacToeMove: Hashable {
66
let row: Int
@@ -12,14 +12,14 @@ public struct TicTacToeMove: Hashable {
1212
}
1313

1414
public init(fromString str: String) throws {
15-
if let parsedArgs = argsRegex.firstGroups(in: str) {
16-
if let row = Row(rawValue: parsedArgs[1]), let column = Column(rawValue: parsedArgs[2]) {
15+
if let parsedArgs = try? argsRegex.firstMatch(in: str) {
16+
if let row = Row(rawValue: String(parsedArgs.1)), let column = Column(rawValue: String(parsedArgs.2)) {
1717
self.row = row.index
1818
self.column = column.index
19-
} else if let row = Row(rawValue: parsedArgs[2]), let column = Column(rawValue: parsedArgs[1]) {
19+
} else if let row = Row(rawValue: String(parsedArgs.2)), let column = Column(rawValue: String(parsedArgs.1)) {
2020
self.row = row.index
2121
self.column = column.index
22-
} else if let row = Int(parsedArgs[1]), let column = Int(parsedArgs[2]) {
22+
} else if let row = Int(parsedArgs.1), let column = Int(parsedArgs.2) {
2323
self.row = row
2424
self.column = column
2525
} else {

0 commit comments

Comments
 (0)