1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-11-11 01:42:35 +03:00
Macaw/Source/svg/SVGParserRegexHelper.swift

73 lines
2.5 KiB
Swift
Raw Normal View History

import Foundation
2016-08-12 14:12:20 +03:00
class SVGParserRegexHelper {
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]+)$"
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?
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
}
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
}
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
}
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
}
}