mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-21 09:59:10 +03:00
Clean up numbers reading code in SVGParser
This commit is contained in:
parent
da66d92489
commit
e5dbc44ff4
@ -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() {
|
||||||
|
data.append(value)
|
||||||
|
} else {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
if getPathSegmentType() != nil || readNext() == nil {
|
|
||||||
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!)) {
|
||||||
|
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) {
|
while let ch = readDigit(&hasDot) {
|
||||||
chars.append(ch)
|
chars.append(ch)
|
||||||
}
|
}
|
||||||
var buf = ""
|
var buf = ""
|
||||||
buf.unicodeScalars.append(contentsOf: chars)
|
buf.unicodeScalars.append(contentsOf: chars)
|
||||||
return buf
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user