]> git.r.bdr.sh - rbdr/map/blame - Map/Logic/MapParser/Strategies/BlockerParserStrategy.swift
Begin re-licensing
[rbdr/map] / Map / Logic / MapParser / Strategies / BlockerParserStrategy.swift
CommitLineData
77d0155b
RBR
1import Foundation
2
3struct BlockerParserStrategy: MapParserStrategy {
4 private let regex = MapParsingPatterns.blocker
5
6 func canHandle(line: String) -> Bool {
7 let range = NSRange(location: 0, length: line.utf16.count)
8 let matches = regex.matches(in: String(line), options: [], range: range)
9 return matches.count > 0 && matches[0].numberOfRanges == 3
10 }
11
12 func handle(index: Int, line: String, vertices: [String: Vertex]) -> (Any.Type, Any) {
13 let range = NSRange(location: 0, length: line.utf16.count)
14 let matches = regex.matches(in: String(line), options: [], range: range)
15
16 let match = matches[0]
17 let vertexA = String(line[Range(match.range(at: 2), in: line)!])
18
19 if let vertex = vertices[vertexA] {
20 let blocker = Blocker(id: index, position: vertex.position)
21 return (Blocker.self, blocker)
22 }
23
24 return (NSObject.self, NSObject()) // No matching object
25 }
26}