1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-11-10 13:16:41 +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] {
var data = [Double]()
while true {
while !isNumStart() {
if !isAcceptableSeparator(current) {
skipSpaces()
if let value = readNum() {
data.append(value)
} else {
return data
}
if getPathSegmentType() != nil || readNext() == nil {
return data
}
}
if let double = Double(readNum()) {
data.append(double)
}
}
}
fileprivate func readNum() -> String {
var chars = [current!]
var hasDot = current == "."
private func skipSpaces() {
var ch = current
while ch != nil && "\n\r\t ,".contains(String(ch!)) {
ch = readNext()
}
}
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 buf
return Double(buf)
}
return nil
}
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 {