Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dileping committed Mar 31, 2017
2 parents 94664e8 + 7cb07d1 commit 68cf0d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CrossroadRegex.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CrossroadRegex'
s.version = '1.0.0-alpha.1'
s.version = '1.0.0'
s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }
s.summary = 'Easy, portable and feature reach Regular Expressions for Swift'
s.homepage = 'https://github.com/crossroadlabs/Regex'
Expand Down
3 changes: 1 addition & 2 deletions Sources/Regex/PlatformTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import Foundation
typealias CompiledPatternMatch = NSTextCheckingResult
typealias GroupRange = NSRange
#else
//here we use NSRegularExpression
typealias CompiledPattern = RegularExpression
typealias CompiledPattern = NSRegularExpression
typealias CompiledMatchContext = [TextCheckingResult]
typealias CompiledPatternMatch = TextCheckingResult
typealias GroupRange = NSRange
Expand Down
8 changes: 4 additions & 4 deletions Sources/Regex/Regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public class Regex : RegexProtocol {

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

/**
Expand All @@ -231,7 +231,7 @@ public class Regex : RegexProtocol {
- returns: A sequense of found matches. Can be empty if nothing was found.
*/
public func findAll(in source:String) -> MatchSequence {
let options = RegularExpression.MatchingOptions(rawValue: 0)
let options = NSRegularExpression.MatchingOptions(rawValue: 0)
let range = GroupRange(location: 0, length: source.characters.count)
let context = compiled?.matches(in: source, options: options, range: range)
//hard unwrap of context, because the instance would not exist without it
Expand All @@ -246,7 +246,7 @@ public class Regex : RegexProtocol {
- returns: The match. Can be .none if nothing was found
*/
public func findFirst(in source:String) -> Match? {
let options = RegularExpression.MatchingOptions(rawValue: 0)
let options = NSRegularExpression.MatchingOptions(rawValue: 0)
let range = GroupRange(location: 0, length: source.characters.count)
let match = compiled?.firstMatch(in: source, options: options, range: range)
return match.map { match in
Expand All @@ -263,7 +263,7 @@ public class Regex : RegexProtocol {
- returns: A string, where all the occurances of the pattern were replaced.
*/
public func replaceAll(in source:String, with replacement:String) -> String {
let options = RegularExpression.MatchingOptions(rawValue: 0)
let options = NSRegularExpression.MatchingOptions(rawValue: 0)
let range = GroupRange(location: 0, length: source.characters.count)

return compiled!.stringByReplacingMatches(in: source, options: options, range: range, withTemplate: replacement)
Expand Down
21 changes: 8 additions & 13 deletions Sources/Regex/RegexOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,11 @@ public struct RegexOptions : OptionSet {
public static let `default`:RegexOptions = [caseInsensitive]
}

#if !os(Linux)
#if os(Linux)
/**
* Internal implementation that can't be hidden. Skip it.
*/
typealias RegularExpression = NSRegularExpression
#else
/**
* Internal implementation that can't be hidden. Skip it.
*/
extension RegularExpression {
extension NSRegularExpression {
/**
* Internal implementation that can't be hidden. Skip it.
*/
Expand All @@ -98,7 +93,7 @@ public struct RegexOptions : OptionSet {
/**
* Internal implementation that can't be hidden. Skip it.
*/
extension RegularExpression.Options : Hashable {
extension NSRegularExpression.Options : Hashable {
/**
* Internal implementation that can't be hidden. Skip it.
*/
Expand All @@ -123,7 +118,7 @@ extension RegexOptions : Hashable {
}
}

private let nsToRegexOptionsMap:Dictionary<RegularExpression.Options, RegexOptions> = [
private let nsToRegexOptionsMap:Dictionary<NSRegularExpression.Options, RegexOptions> = [
.caseInsensitive:.caseInsensitive,
.allowCommentsAndWhitespace:.allowCommentsAndWhitespace,
.ignoreMetacharacters:.ignoreMetacharacters,
Expand All @@ -132,7 +127,7 @@ private let nsToRegexOptionsMap:Dictionary<RegularExpression.Options, RegexOptio
.useUnixLineSeparators:.useUnixLineSeparators,
.useUnicodeWordBoundaries:.useUnicodeWordBoundaries]

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

extension RegexOptions {
var ns:RegularExpression.Options {
var ns: NSRegularExpression.Options {
get {
let nsSeq = regexToNSOptionsMap.filter { (regex, _) in
self.contains(regex)
}.map { (_, ns) in
ns
}

return RegularExpression.Options(nsSeq)
return NSRegularExpression.Options(nsSeq)
}
}
}

extension RegularExpression.Options {
extension NSRegularExpression.Options {
var regex:RegexOptions {
get {
let regexSeq = nsToRegexOptionsMap.filter { (ns, _) in
Expand Down

0 comments on commit 68cf0d2

Please sign in to comment.