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

Add grammar checks to style parser

This commit is contained in:
Yuriy Kashnikov 2017-10-03 17:11:13 +07:00
parent 5de677eefe
commit 20d48db7ab

View File

@ -104,16 +104,20 @@ open class SVGParser {
if let rawStyle = styleNode.element?.text { if let rawStyle = styleNode.element?.text {
var styleAttributes: [String: String] = [:] var styleAttributes: [String: String] = [:]
let parts = rawStyle.trimmingCharacters(in: .whitespacesAndNewlines).split(separator: "{") let parts = rawStyle.trimmingCharacters(in: .whitespacesAndNewlines).split(separator: "{")
let className = String(parts[0].dropFirst()) if parts.count == 2 {
let style = String(parts[1].dropLast()) let className = String(parts[0].dropFirst())
let styleParts = style.replacingOccurrences(of: " ", with: "").components(separatedBy: ";") if !className.isEmpty {
styleParts.forEach { styleAttribute in let style = String(parts[1].dropLast())
let currentStyle = styleAttribute.components(separatedBy: ":") let styleParts = style.replacingOccurrences(of: " ", with: "").components(separatedBy: ";")
if currentStyle.count == 2 { styleParts.forEach { styleAttribute in
styleAttributes.updateValue(currentStyle[1], forKey: currentStyle[0]) let currentStyle = styleAttribute.components(separatedBy: ":")
if currentStyle.count == 2 {
styleAttributes.updateValue(currentStyle[1], forKey: currentStyle[0])
}
}
styleTable[className] = styleAttributes
} }
} }
styleTable[className] = styleAttributes
} }
} }