import Foundation struct NoteParserStrategy: MapParserStrategy { private let regex = MapParsingPatterns.note func canHandle(line: String) -> Bool { let range = NSRange(location: 0, length: line.utf16.count) let matches = regex.matches(in: String(line), options: [], range: range) return matches.count > 0 && matches[0].numberOfRanges == 5 } func handle(index: Int, line: String, vertices: [String: Vertex]) -> (Any.Type, Any) { let range = NSRange(location: 0, length: line.utf16.count) let matches = regex.matches(in: String(line), options: [], range: range) let match = matches[0] let text = String(line[Range(match.range(at: 4), in: line)!]) let xString = String(line[Range(match.range(at: 2), in: line)!]) let yString = String(line[Range(match.range(at: 3), in: line)!]) let x = CGFloat(truncating: NumberFormatter().number(from: xString) ?? 0.0) let y = CGFloat(truncating: NumberFormatter().number(from: yString) ?? 0.0) let note = Note( id: index, position: CGPoint(x: x, y: y), text: text ) return (Note.self, note) } }