Files
SwiftLint/Source/SwiftLintFramework/Extensions/NSRegularExpression+SwiftLint.swift
T
Norio Nomura 7c12a63e8f Merge commit '58eb0f69c4055bb2cb89b3df278eca6ce0fb1c34' into swift3.0
* commit '58eb0f69c4055bb2cb89b3df278eca6ce0fb1c34':
  generally clean up usage of swiftlint comment commands
  update README to reflect the ability to specify multiple rules in commands
  add changelog entry
  allow specifying multiple rule identifiers in comment commands

# Conflicts:
#	Source/SwiftLintFramework/Extensions/NSRegularExpression+SwiftLint.swift
#	Source/SwiftLintFramework/Models/Command.swift
#	Source/SwiftLintFramework/Rules/LegacyNSGeometryFunctionsRule.swift
#	Tests/SwiftLintFrameworkTests/ConfigurationTests.swift
#	Tests/SwiftLintFrameworkTests/IntegrationTests.swift
2016-11-30 18:42:40 +09:00

30 lines
804 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: 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)
}
}