2016-09-20 18:17:58 +03:00
|
|
|
import Foundation
|
|
|
|
|
2016-08-12 14:12:20 +03:00
|
|
|
class SVGParserRegexHelper {
|
2017-10-16 12:11:41 +03:00
|
|
|
|
|
|
|
fileprivate static let transformAttributePattern = "([a-z]+)\\(((\\-?\\d+\\.?\\d*e?\\-?\\d*\\s*,?\\s*)+)\\)"
|
|
|
|
fileprivate static let transformPattern = "\\-?\\d+\\.?\\d*e?\\-?\\d*"
|
|
|
|
fileprivate static let textElementPattern = "<text.*?>((?s:.*))<\\/text>"
|
|
|
|
fileprivate static let maskIdenitifierPattern = "url\\(#((?s:.*))\\)"
|
2018-04-23 13:08:12 +03:00
|
|
|
fileprivate static let unitsIdenitifierPattern = "([a-zA-Z]+)$"
|
2017-10-16 12:11:41 +03:00
|
|
|
|
|
|
|
fileprivate static var transformMatcher: NSRegularExpression?
|
|
|
|
fileprivate static var transformAttributeMatcher: NSRegularExpression?
|
|
|
|
fileprivate static var textElementMatcher: NSRegularExpression?
|
|
|
|
fileprivate static var maskIdenitifierMatcher: NSRegularExpression?
|
2018-04-23 13:08:12 +03:00
|
|
|
fileprivate static var unitsMatcher: NSRegularExpression?
|
2017-10-16 12:11:41 +03:00
|
|
|
|
|
|
|
class func getTransformAttributeMatcher() -> NSRegularExpression? {
|
|
|
|
if self.transformAttributeMatcher == nil {
|
|
|
|
do {
|
|
|
|
self.transformAttributeMatcher = try NSRegularExpression(pattern: transformAttributePattern, options: .caseInsensitive)
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self.transformAttributeMatcher
|
2016-08-12 14:12:20 +03:00
|
|
|
}
|
2017-10-16 12:11:41 +03:00
|
|
|
|
|
|
|
class func getTransformMatcher() -> NSRegularExpression? {
|
|
|
|
if self.transformMatcher == nil {
|
|
|
|
do {
|
|
|
|
self.transformMatcher = try NSRegularExpression(pattern: transformPattern, options: .caseInsensitive)
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self.transformMatcher
|
2016-08-12 14:12:20 +03:00
|
|
|
}
|
2017-10-16 12:11:41 +03:00
|
|
|
|
|
|
|
class func getTextElementMatcher() -> NSRegularExpression? {
|
|
|
|
if self.textElementMatcher == nil {
|
|
|
|
do {
|
|
|
|
self.textElementMatcher = try NSRegularExpression(pattern: textElementPattern, options: .caseInsensitive)
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self.textElementMatcher
|
2016-08-12 14:12:20 +03:00
|
|
|
}
|
2017-10-16 12:11:41 +03:00
|
|
|
|
|
|
|
class func getMaskIdenitifierMatcher() -> NSRegularExpression? {
|
|
|
|
if self.maskIdenitifierMatcher == nil {
|
|
|
|
do {
|
|
|
|
self.maskIdenitifierMatcher = try NSRegularExpression(pattern: maskIdenitifierPattern, options: .caseInsensitive)
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self.maskIdenitifierMatcher
|
2016-12-02 10:19:53 +03:00
|
|
|
}
|
2018-05-16 19:40:04 +03:00
|
|
|
|
2018-04-23 13:08:12 +03:00
|
|
|
class func getUnitsIdenitifierMatcher() -> NSRegularExpression? {
|
|
|
|
if unitsMatcher == nil {
|
|
|
|
do {
|
|
|
|
unitsMatcher = try NSRegularExpression(pattern: unitsIdenitifierPattern, options: .caseInsensitive)
|
|
|
|
} catch {
|
2018-05-16 19:40:04 +03:00
|
|
|
|
2018-04-23 13:08:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return unitsMatcher
|
|
|
|
}
|
2017-10-16 12:11:41 +03:00
|
|
|
|
2016-09-20 18:17:58 +03:00
|
|
|
}
|