Files
SwiftLint/Source/SwiftLintFramework/Extensions/NSRegularExpression+SwiftLint.swift
T
JP Simard 1866edae77 adjust access control levels for many APIs in SwiftLintFramework
this is done in an effort to stabilize the API for SwiftLint 1.0.
2016-02-10 17:26:06 -08:00

29 lines
828 B
Swift

//
// NSRegularExpression+SwiftLint.swift
// SwiftLint
//
// Created by Scott Hoyt on 1/21/16.
// Copyright © 2016 Realm. All rights reserved.
//
import Foundation
private var regexCache = [String: NSRegularExpression]()
extension NSRegularExpression {
internal static func cached(pattern pattern: String) throws -> NSRegularExpression {
if let result = regexCache[pattern] {
return result
}
let result = try NSRegularExpression(pattern: pattern,
options: [.AnchorsMatchLines, .DotMatchesLineSeparators])
regexCache[pattern] = result
return result
}
internal static func forcePattern(pattern: String) -> NSRegularExpression {
// swiftlint:disable:next force_try
return try! NSRegularExpression.cached(pattern: pattern)
}
}