no message

This commit is contained in:
Peter
2016-08-16 14:02:36 +03:00
parent a31c0a3e40
commit 766fcbbb95
316 changed files with 94427 additions and 11 deletions

33
TelegramCore/Regex.swift Normal file
View File

@@ -0,0 +1,33 @@
import Foundation
struct Regex {
let pattern: String
let options: NSRegularExpression.Options!
private var matcher: NSRegularExpression {
return try! NSRegularExpression(pattern: self.pattern, options: self.options)
}
init(_ pattern: String) {
self.pattern = pattern
self.options = []
}
func match(_ string: String, options: NSRegularExpression.MatchingOptions = []) -> Bool {
return self.matcher.numberOfMatches(in: string, options: options, range: NSMakeRange(0, string.utf16.count)) != 0
}
}
protocol RegularExpressionMatchable {
func match(_ regex: Regex) -> Bool
}
extension String: RegularExpressionMatchable {
func match(_ regex: Regex) -> Bool {
return regex.match(self)
}
}
func ~=<T: RegularExpressionMatchable>(pattern: Regex, matchable: T) -> Bool {
return matchable.match(pattern)
}