Skip to content

Change RegularExpression back to NSRegularExpression #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Foundation/NSRegularExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import CoreFoundation

extension RegularExpression {
extension NSRegularExpression {
public struct Options : OptionSet {
public let rawValue : UInt
public init(rawValue: UInt) { self.rawValue = rawValue }
Expand All @@ -27,7 +27,7 @@ extension RegularExpression {
}
}

open class RegularExpression: NSObject, NSCopying, NSCoding {
open class NSRegularExpression: NSObject, NSCopying, NSCoding {
internal var _internal: _CFRegularExpression

open override func copy() -> Any {
Expand Down Expand Up @@ -112,9 +112,9 @@ public struct NSMatchingFlags : OptionSet {
}

internal class _NSRegularExpressionMatcher {
var regex: RegularExpression
var regex: NSRegularExpression
var block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
init(regex: RegularExpression, block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
init(regex: NSRegularExpression, block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
self.regex = regex
self.block = block
}
Expand Down Expand Up @@ -146,7 +146,7 @@ internal func _NSRegularExpressionMatch(_ context: UnsafeMutableRawPointer?, ran
}
}

extension RegularExpression {
extension NSRegularExpression {

/* The fundamental matching method on NSRegularExpression is a block iterator. There are several additional convenience methods, for returning all matches at once, the number of matches, the first match, or the range of the first match. Each match is specified by an instance of NSTextCheckingResult (of type NSTextCheckingTypeRegularExpression) in which the overall match range is given by the range property (equivalent to range at:0) and any capture group ranges are given by range at: for indexes from 1 to numberOfCaptureGroups. {NSNotFound, 0} is used if a particular capture group does not participate in the match.
*/
Expand Down Expand Up @@ -214,7 +214,7 @@ NSMatchingAnchored, NSMatchingWithTransparentBounds, and NSMatchingWithoutAnchor
NSRegularExpression is designed to be immutable and threadsafe, so that a single instance can be used in matching operations on multiple threads at once. However, the string on which it is operating should not be mutated during the course of a matching operation (whether from another thread or from within the block used in the iteration).
*/

extension RegularExpression {
extension NSRegularExpression {

/* NSRegularExpression also provides find-and-replace methods for both immutable and mutable strings. The replacement is treated as a template, with $0 being replaced by the contents of the matched range, $1 by the contents of the first capture group, and so on. Additional digits beyond the maximum required to represent the number of capture groups will be treated as ordinary characters, as will a $ not followed by digits. Backslash will escape both $ and itself.
*/
Expand Down
14 changes: 7 additions & 7 deletions Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ extension NSString {
}
}

internal func _createRegexForPattern(_ pattern: String, _ options: RegularExpression.Options) -> RegularExpression? {
internal func _createRegexForPattern(_ pattern: String, _ options: NSRegularExpression.Options) -> NSRegularExpression? {
struct local {
static let __NSRegularExpressionCache: NSCache<NSString, RegularExpression> = {
let cache = NSCache<NSString, RegularExpression>()
static let __NSRegularExpressionCache: NSCache<NSString, NSRegularExpression> = {
let cache = NSCache<NSString, NSRegularExpression>()
cache.name = "NSRegularExpressionCache"
cache.countLimit = 10
return cache
Expand All @@ -115,7 +115,7 @@ internal func _createRegexForPattern(_ pattern: String, _ options: RegularExpres
return regex
}
do {
let regex = try RegularExpression(pattern: pattern, options: options)
let regex = try NSRegularExpression(pattern: pattern, options: options)
local.__NSRegularExpressionCache.setObject(regex, forKey: key._nsObject)
return regex
} catch {
Expand Down Expand Up @@ -487,7 +487,7 @@ extension NSString {

internal func _rangeOfRegularExpressionPattern(regex pattern: String, options mask: CompareOptions, range searchRange: NSRange, locale: Locale?) -> NSRange {
var matchedRange = NSMakeRange(NSNotFound, 0)
let regexOptions: RegularExpression.Options = mask.contains(.caseInsensitive) ? .caseInsensitive : []
let regexOptions: NSRegularExpression.Options = mask.contains(.caseInsensitive) ? .caseInsensitive : []
let matchingOptions: NSMatchingOptions = mask.contains(.anchored) ? .anchored : []
if let regex = _createRegexForPattern(pattern, regexOptions) {
matchedRange = regex.rangeOfFirstMatch(in: _swiftObject, options: matchingOptions, range: searchRange)
Expand Down Expand Up @@ -1054,7 +1054,7 @@ extension NSString {
}

internal func _stringByReplacingOccurrencesOfRegularExpressionPattern(_ pattern: String, withTemplate replacement: String, options: CompareOptions, range: NSRange) -> String {
let regexOptions: RegularExpression.Options = options.contains(.caseInsensitive) ? .caseInsensitive : []
let regexOptions: NSRegularExpression.Options = options.contains(.caseInsensitive) ? .caseInsensitive : []
let matchingOptions: NSMatchingOptions = options.contains(.anchored) ? .anchored : []
if let regex = _createRegexForPattern(pattern, regexOptions) {
return regex.stringByReplacingMatches(in: _swiftObject, options: matchingOptions, range: range, withTemplate: replacement)
Expand Down Expand Up @@ -1341,7 +1341,7 @@ extension NSMutableString {
}

internal func _replaceOccurrencesOfRegularExpressionPattern(_ pattern: String, withTemplate replacement: String, options: CompareOptions, range searchRange: NSRange) -> Int {
let regexOptions: RegularExpression.Options = options.contains(.caseInsensitive) ? .caseInsensitive : []
let regexOptions: NSRegularExpression.Options = options.contains(.caseInsensitive) ? .caseInsensitive : []
let matchingOptions: NSMatchingOptions = options.contains(.anchored) ? .anchored : []
if let regex = _createRegexForPattern(pattern, regexOptions) {
return regex.replaceMatches(in: self, options: matchingOptions, range: searchRange, withTemplate: replacement)
Expand Down
10 changes: 5 additions & 5 deletions Foundation/NSTextCheckingResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class TextCheckingResult: NSObject, NSCopying, NSCoding {
super.init()
}

open class func regularExpressionCheckingResultWithRanges(_ ranges: NSRangePointer, count: Int, regularExpression: RegularExpression) -> TextCheckingResult {
open class func regularExpressionCheckingResultWithRanges(_ ranges: NSRangePointer, count: Int, regularExpression: NSRegularExpression) -> TextCheckingResult {
return _NSRegularExpressionTextCheckingResultResult(ranges: ranges, count: count, regularExpression: regularExpression)
}

Expand All @@ -50,14 +50,14 @@ open class TextCheckingResult: NSObject, NSCopying, NSCoding {
open var range: NSRange { return range(at: 0) }
/* A result must have at least one range, but may optionally have more (for example, to represent regular expression capture groups). The range at index 0 always matches the range property. Additional ranges, if any, will have indexes from 1 to numberOfRanges-1. */
open func range(at idx: Int) -> NSRange { NSUnimplemented() }
open var regularExpression: RegularExpression? { return nil }
open var regularExpression: NSRegularExpression? { return nil }
open var numberOfRanges: Int { return 1 }
}

internal class _NSRegularExpressionTextCheckingResultResult : TextCheckingResult {
var _ranges = [NSRange]()
let _regularExpression: RegularExpression
init(ranges: NSRangePointer, count: Int, regularExpression: RegularExpression) {
let _regularExpression: NSRegularExpression
init(ranges: NSRangePointer, count: Int, regularExpression: NSRegularExpression) {
_regularExpression = regularExpression
super.init()
let notFound = NSRange(location: NSNotFound,length: 0)
Expand All @@ -73,7 +73,7 @@ internal class _NSRegularExpressionTextCheckingResultResult : TextCheckingResult
override var resultType: CheckingType { return .RegularExpression }
override func range(at idx: Int) -> NSRange { return _ranges[idx] }
override var numberOfRanges: Int { return _ranges.count }
override var regularExpression: RegularExpression? { return _regularExpression }
override var regularExpression: NSRegularExpression? { return _regularExpression }
}

extension TextCheckingResult {
Expand Down
Loading