mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
97392bdc94
All rules enabled linting Carthage 0.11 with this commit: - Persistent Bytes on termination is reduced from 584.67MB to 556.62MB. - Duration is reduced from 22sec to 21sec. Related: #394
29 lines
831 B
Swift
29 lines
831 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]()
|
|
|
|
public extension NSRegularExpression {
|
|
public 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
|
|
}
|
|
public static func forcePattern(pattern: String) -> NSRegularExpression {
|
|
// swiftlint:disable:next force_try
|
|
return try! NSRegularExpression.cached(pattern: pattern)
|
|
}
|
|
}
|