From bd5e868daca30f5bde78cef52fde6f951b4c3512 Mon Sep 17 00:00:00 2001 From: Petrov Anatoly Date: Wed, 29 Apr 2020 15:45:26 +0700 Subject: [PATCH] Fix polyline and polygon points parsing Handling of numbers in scientific notation in `parsePoints` used to be incorrect, because a number could be broken by an exponent minus sign, resulting in incorrect values. E.g. '2.5e-1' -> '2.5e', '-1'. --- Source/svg/SVGParser.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/svg/SVGParser.swift b/Source/svg/SVGParser.swift index f3e0a7c6..5bb08a77 100644 --- a/Source/svg/SVGParser.swift +++ b/Source/svg/SVGParser.swift @@ -986,15 +986,14 @@ open class SVGParser { fileprivate func parsePoints(_ pointsString: String) -> [Double] { var resultPoints: [Double] = [] - let pointPairs = pointsString.replacingOccurrences(of: "-", with: " -").components(separatedBy: " ") - pointPairs.forEach { pointPair in - let points = pointPair.components(separatedBy: ",") - points.forEach { point in - if let resultPoint = Double(point) { - resultPoints.append(resultPoint) - } + let scanner = Scanner(string: pointsString) + while !scanner.isAtEnd { + var resultPoint: Double = 0 + if scanner.scanDouble(&resultPoint) { + resultPoints.append(resultPoint) } + _ = scanner.scanCharacters(from: [","], into: nil) } if resultPoints.count % 2 == 1 {