mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
e93eee31e7
used within the codebase itself.
30 lines
810 B
Swift
30 lines
810 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! .cached(pattern: pattern)
|
|
}
|
|
}
|