Skip to content

Commit a4a1165

Browse files
author
Pushkar N Kulkarni
committed
Change RegularExpression back to NSRegularExpression
1 parent 618f82d commit a4a1165

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

Foundation/NSRegularExpression.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import CoreFoundation
1414

15-
extension RegularExpression {
15+
extension NSRegularExpression {
1616
public struct Options : OptionSet {
1717
public let rawValue : UInt
1818
public init(rawValue: UInt) { self.rawValue = rawValue }
@@ -27,7 +27,7 @@ extension RegularExpression {
2727
}
2828
}
2929

30-
open class RegularExpression: NSObject, NSCopying, NSCoding {
30+
open class NSRegularExpression: NSObject, NSCopying, NSCoding {
3131
internal var _internal: _CFRegularExpression
3232

3333
open override func copy() -> Any {
@@ -112,9 +112,9 @@ public struct NSMatchingFlags : OptionSet {
112112
}
113113

114114
internal class _NSRegularExpressionMatcher {
115-
var regex: RegularExpression
115+
var regex: NSRegularExpression
116116
var block: (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
117-
init(regex: RegularExpression, block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
117+
init(regex: NSRegularExpression, block: @escaping (TextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void) {
118118
self.regex = regex
119119
self.block = block
120120
}
@@ -146,7 +146,7 @@ internal func _NSRegularExpressionMatch(_ context: UnsafeMutableRawPointer?, ran
146146
}
147147
}
148148

149-
extension RegularExpression {
149+
extension NSRegularExpression {
150150

151151
/* 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.
152152
*/
@@ -214,7 +214,7 @@ NSMatchingAnchored, NSMatchingWithTransparentBounds, and NSMatchingWithoutAnchor
214214
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).
215215
*/
216216

217-
extension RegularExpression {
217+
extension NSRegularExpression {
218218

219219
/* 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.
220220
*/

Foundation/NSString.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ extension NSString {
101101
}
102102
}
103103

104-
internal func _createRegexForPattern(_ pattern: String, _ options: RegularExpression.Options) -> RegularExpression? {
104+
internal func _createRegexForPattern(_ pattern: String, _ options: NSRegularExpression.Options) -> NSRegularExpression? {
105105
struct local {
106-
static let __NSRegularExpressionCache: NSCache<NSString, RegularExpression> = {
107-
let cache = NSCache<NSString, RegularExpression>()
106+
static let __NSRegularExpressionCache: NSCache<NSString, NSRegularExpression> = {
107+
let cache = NSCache<NSString, NSRegularExpression>()
108108
cache.name = "NSRegularExpressionCache"
109109
cache.countLimit = 10
110110
return cache
@@ -115,7 +115,7 @@ internal func _createRegexForPattern(_ pattern: String, _ options: RegularExpres
115115
return regex
116116
}
117117
do {
118-
let regex = try RegularExpression(pattern: pattern, options: options)
118+
let regex = try NSRegularExpression(pattern: pattern, options: options)
119119
local.__NSRegularExpressionCache.setObject(regex, forKey: key._nsObject)
120120
return regex
121121
} catch {
@@ -487,7 +487,7 @@ extension NSString {
487487

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

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

13431343
internal func _replaceOccurrencesOfRegularExpressionPattern(_ pattern: String, withTemplate replacement: String, options: CompareOptions, range searchRange: NSRange) -> Int {
1344-
let regexOptions: RegularExpression.Options = options.contains(.caseInsensitive) ? .caseInsensitive : []
1344+
let regexOptions: NSRegularExpression.Options = options.contains(.caseInsensitive) ? .caseInsensitive : []
13451345
let matchingOptions: NSMatchingOptions = options.contains(.anchored) ? .anchored : []
13461346
if let regex = _createRegexForPattern(pattern, regexOptions) {
13471347
return regex.replaceMatches(in: self, options: matchingOptions, range: searchRange, withTemplate: replacement)

Foundation/NSTextCheckingResult.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ open class TextCheckingResult: NSObject, NSCopying, NSCoding {
2525
super.init()
2626
}
2727

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

@@ -50,14 +50,14 @@ open class TextCheckingResult: NSObject, NSCopying, NSCoding {
5050
open var range: NSRange { return range(at: 0) }
5151
/* 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. */
5252
open func range(at idx: Int) -> NSRange { NSUnimplemented() }
53-
open var regularExpression: RegularExpression? { return nil }
53+
open var regularExpression: NSRegularExpression? { return nil }
5454
open var numberOfRanges: Int { return 1 }
5555
}
5656

5757
internal class _NSRegularExpressionTextCheckingResultResult : TextCheckingResult {
5858
var _ranges = [NSRange]()
59-
let _regularExpression: RegularExpression
60-
init(ranges: NSRangePointer, count: Int, regularExpression: RegularExpression) {
59+
let _regularExpression: NSRegularExpression
60+
init(ranges: NSRangePointer, count: Int, regularExpression: NSRegularExpression) {
6161
_regularExpression = regularExpression
6262
super.init()
6363
let notFound = NSRange(location: NSNotFound,length: 0)
@@ -73,7 +73,7 @@ internal class _NSRegularExpressionTextCheckingResultResult : TextCheckingResult
7373
override var resultType: CheckingType { return .RegularExpression }
7474
override func range(at idx: Int) -> NSRange { return _ranges[idx] }
7575
override var numberOfRanges: Int { return _ranges.count }
76-
override var regularExpression: RegularExpression? { return _regularExpression }
76+
override var regularExpression: NSRegularExpression? { return _regularExpression }
7777
}
7878

7979
extension TextCheckingResult {

0 commit comments

Comments
 (0)