-
Notifications
You must be signed in to change notification settings - Fork 1
/
Predicate+String.swift
35 lines (27 loc) · 975 Bytes
/
Predicate+String.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// Created by Oleksii Chernysh on 06.11.17.
// Copyright © 2017 Oleksii Chernysh. All rights reserved.
//
import Foundation
func lengthEquals(_ length: Int) -> Predicate<String> {
return Predicate { $0.characters.count == length }
}
func longerThan(_ length: Int) -> Predicate<String> {
return Predicate { $0.characters.count > length }
}
func shorterThan(_ length: Int) -> Predicate<String> {
return Predicate { $0.characters.count < length }
}
func containsString(_ otherString: String) -> Predicate<String> {
return Predicate { $0.contains(otherString) }
}
func hasPrefix(_ prefix: String) -> Predicate<String> {
return Predicate { $0.hasPrefix(prefix) }
}
func hasSuffix(_ suffix: String) -> Predicate<String> {
return Predicate { $0.hasSuffix(suffix) }
}
func matchingRegExp(_ pattern: String) -> Predicate<String> {
let predicate = NSPredicate(format: "SELF MATCHES %@", pattern)
return Predicate { return predicate.evaluate(with: $0) }
}