Skip to content

Commit 68cf0d2

Browse files
committed
Merge branch 'develop'
2 parents 94664e8 + 7cb07d1 commit 68cf0d2

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

CrossroadRegex.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CrossroadRegex'
3-
s.version = '1.0.0-alpha.1'
3+
s.version = '1.0.0'
44
s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }
55
s.summary = 'Easy, portable and feature reach Regular Expressions for Swift'
66
s.homepage = 'https://github.com/crossroadlabs/Regex'

Sources/Regex/PlatformTypes.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import Foundation
2323
typealias CompiledPatternMatch = NSTextCheckingResult
2424
typealias GroupRange = NSRange
2525
#else
26-
//here we use NSRegularExpression
27-
typealias CompiledPattern = RegularExpression
26+
typealias CompiledPattern = NSRegularExpression
2827
typealias CompiledMatchContext = [TextCheckingResult]
2928
typealias CompiledPatternMatch = TextCheckingResult
3029
typealias GroupRange = NSRange

Sources/Regex/Regex.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public class Regex : RegexProtocol {
220220

221221
private static func compile(pattern:String, options:RegexOptions) throws -> CompiledPattern {
222222
//pass options
223-
return try RegularExpression(pattern: pattern, options: options.ns)
223+
return try NSRegularExpression(pattern: pattern, options: options.ns)
224224
}
225225

226226
/**
@@ -231,7 +231,7 @@ public class Regex : RegexProtocol {
231231
- returns: A sequense of found matches. Can be empty if nothing was found.
232232
*/
233233
public func findAll(in source:String) -> MatchSequence {
234-
let options = RegularExpression.MatchingOptions(rawValue: 0)
234+
let options = NSRegularExpression.MatchingOptions(rawValue: 0)
235235
let range = GroupRange(location: 0, length: source.characters.count)
236236
let context = compiled?.matches(in: source, options: options, range: range)
237237
//hard unwrap of context, because the instance would not exist without it
@@ -246,7 +246,7 @@ public class Regex : RegexProtocol {
246246
- returns: The match. Can be .none if nothing was found
247247
*/
248248
public func findFirst(in source:String) -> Match? {
249-
let options = RegularExpression.MatchingOptions(rawValue: 0)
249+
let options = NSRegularExpression.MatchingOptions(rawValue: 0)
250250
let range = GroupRange(location: 0, length: source.characters.count)
251251
let match = compiled?.firstMatch(in: source, options: options, range: range)
252252
return match.map { match in
@@ -263,7 +263,7 @@ public class Regex : RegexProtocol {
263263
- returns: A string, where all the occurances of the pattern were replaced.
264264
*/
265265
public func replaceAll(in source:String, with replacement:String) -> String {
266-
let options = RegularExpression.MatchingOptions(rawValue: 0)
266+
let options = NSRegularExpression.MatchingOptions(rawValue: 0)
267267
let range = GroupRange(location: 0, length: source.characters.count)
268268

269269
return compiled!.stringByReplacingMatches(in: source, options: options, range: range, withTemplate: replacement)

Sources/Regex/RegexOptions.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,11 @@ public struct RegexOptions : OptionSet {
7878
public static let `default`:RegexOptions = [caseInsensitive]
7979
}
8080

81-
#if !os(Linux)
81+
#if os(Linux)
8282
/**
8383
* Internal implementation that can't be hidden. Skip it.
8484
*/
85-
typealias RegularExpression = NSRegularExpression
86-
#else
87-
/**
88-
* Internal implementation that can't be hidden. Skip it.
89-
*/
90-
extension RegularExpression {
85+
extension NSRegularExpression {
9186
/**
9287
* Internal implementation that can't be hidden. Skip it.
9388
*/
@@ -98,7 +93,7 @@ public struct RegexOptions : OptionSet {
9893
/**
9994
* Internal implementation that can't be hidden. Skip it.
10095
*/
101-
extension RegularExpression.Options : Hashable {
96+
extension NSRegularExpression.Options : Hashable {
10297
/**
10398
* Internal implementation that can't be hidden. Skip it.
10499
*/
@@ -123,7 +118,7 @@ extension RegexOptions : Hashable {
123118
}
124119
}
125120

126-
private let nsToRegexOptionsMap:Dictionary<RegularExpression.Options, RegexOptions> = [
121+
private let nsToRegexOptionsMap:Dictionary<NSRegularExpression.Options, RegexOptions> = [
127122
.caseInsensitive:.caseInsensitive,
128123
.allowCommentsAndWhitespace:.allowCommentsAndWhitespace,
129124
.ignoreMetacharacters:.ignoreMetacharacters,
@@ -132,7 +127,7 @@ private let nsToRegexOptionsMap:Dictionary<RegularExpression.Options, RegexOptio
132127
.useUnixLineSeparators:.useUnixLineSeparators,
133128
.useUnicodeWordBoundaries:.useUnicodeWordBoundaries]
134129

135-
private let regexToNSOptionsMap:Dictionary<RegexOptions, RegularExpression.Options> = nsToRegexOptionsMap.map({ (key, value) in
130+
private let regexToNSOptionsMap:Dictionary<RegexOptions, NSRegularExpression.Options> = nsToRegexOptionsMap.map({ (key, value) in
136131
return (value, key)
137132
}).reduce([:], { (dict, kv) in
138133
var dict = dict
@@ -141,20 +136,20 @@ private let regexToNSOptionsMap:Dictionary<RegexOptions, RegularExpression.Optio
141136
})
142137

143138
extension RegexOptions {
144-
var ns:RegularExpression.Options {
139+
var ns: NSRegularExpression.Options {
145140
get {
146141
let nsSeq = regexToNSOptionsMap.filter { (regex, _) in
147142
self.contains(regex)
148143
}.map { (_, ns) in
149144
ns
150145
}
151146

152-
return RegularExpression.Options(nsSeq)
147+
return NSRegularExpression.Options(nsSeq)
153148
}
154149
}
155150
}
156151

157-
extension RegularExpression.Options {
152+
extension NSRegularExpression.Options {
158153
var regex:RegexOptions {
159154
get {
160155
let regexSeq = nsToRegexOptionsMap.filter { (ns, _) in

0 commit comments

Comments
 (0)