1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-21 01:47:44 +03:00

Clean up numbers reading code in SVGParser

This commit is contained in:
Yuri Strot 2018-05-29 17:33:47 +07:00
parent da66d92489
commit e5dbc44ff4

View File

@ -1516,29 +1516,37 @@ private class PathDataReader {
private func readData() -> [Double] { private func readData() -> [Double] {
var data = [Double]() var data = [Double]()
while true { while true {
while !isNumStart() { skipSpaces()
if !isAcceptableSeparator(current) { if let value = readNum() {
return data data.append(value)
} } else {
if getPathSegmentType() != nil || readNext() == nil { return data
return data
}
}
if let double = Double(readNum()) {
data.append(double)
} }
} }
} }
fileprivate func readNum() -> String { private func skipSpaces() {
var chars = [current!] var ch = current
var hasDot = current == "." while ch != nil && "\n\r\t ,".contains(String(ch!)) {
while let ch = readDigit(&hasDot) { ch = readNext()
chars.append(ch)
} }
var buf = "" }
buf.unicodeScalars.append(contentsOf: chars)
return buf fileprivate func readNum() -> Double? {
guard let ch = current else {
return nil
}
if (ch >= "0" && ch <= "9") || ch == "." || ch == "-" {
var chars = [ch]
var hasDot = ch == "."
while let ch = readDigit(&hasDot) {
chars.append(ch)
}
var buf = ""
buf.unicodeScalars.append(contentsOf: chars)
return Double(buf)
}
return nil
} }
fileprivate func readDigit(_ hasDot: inout Bool) -> UnicodeScalar? { fileprivate func readDigit(_ hasDot: inout Bool) -> UnicodeScalar? {
@ -1658,13 +1666,6 @@ private class PathDataReader {
} }
} }
fileprivate func isNumStart() -> Bool {
if let ch = current {
return (ch >= "0" && ch <= "9") || ch == "." || ch == "-"
}
return false
}
} }
fileprivate extension String { fileprivate extension String {