@@ -9,6 +9,7 @@ import Foundation
99infix operator || : LogicalDisjunctionPrecedence
1010infix operator && : LogicalConjunctionPrecedence
1111prefix operator ~
12+ prefix operator !
1213
1314/// An enum representing a string search predicate.
1415public indirect enum StringPredicate {
@@ -33,62 +34,118 @@ public indirect enum StringPredicate {
3334
3435 /// Represents a case-insensitive and diacritic-insensitive search for a given string.
3536 case diacriticAndCaseInsensitive( String )
37+
38+ case negatable( String )
39+
40+ case negatablePredicate( StringPredicate )
3641}
3742
3843/// Returns a `StringPredicate` that performs a logical OR operation between two strings.
44+ /// - Parameters:
45+ /// - lhs: The first string to be evaluated.
46+ /// - rhs: The second string to be evaluated.
47+ /// - Returns: A `StringPredicate` that performs a logical OR operation between two strings.
3948public func || ( lhs: String , rhs: String ) -> StringPredicate {
4049
4150 return . or( [ lhs, rhs] )
4251}
4352
4453/// Returns a `StringPredicate` that performs a logical OR operation between a string and a `StringPredicate`.
54+ /// - Parameters:
55+ /// - lhs: The string to be evaluated.
56+ /// - rhs: The `StringPredicate` to be evaluated.
57+ /// - Returns: A `StringPredicate` that performs a logical OR operation between a string and a `StringPredicate`.
4558public func || ( lhs: String , rhs: StringPredicate ) -> StringPredicate {
4659
4760 return . orPredicates( lhs, rhs)
4861}
4962
5063/// Returns a `StringPredicate` that performs a logical OR operation between a `StringPredicate` and a string.
64+ /// - Parameters:
65+ /// - lhs: The `StringPredicate` to be evaluated.
66+ /// - rhs: The string to be evaluated.
67+ /// - Returns: A `StringPredicate` that performs a logical OR operation between a `StringPredicate` and a string.
5168public func || ( lhs: StringPredicate , rhs: String ) -> StringPredicate {
5269
5370 return . orPredicates( rhs, lhs)
5471}
5572
5673/// Returns a `StringPredicate` that performs a logical OR operation between two `StringPredicate`s.
74+ /// - Parameters:
75+ /// - lhs: The first `StringPredicate` to be evaluated.
76+ /// - rhs: The second `StringPredicate` to be evaluated.
77+ /// - Returns: A `StringPredicate` that performs a logical OR operation between two `StringPredicate`s.
5778public func || ( lhs: StringPredicate , rhs: StringPredicate ) -> StringPredicate {
5879
5980 return . orOnlyPredicates( [ rhs, lhs] )
6081}
6182
6283/// Returns a `StringPredicate` that performs a logical AND operation between two strings.
84+ /// - Parameters:
85+ /// - lhs: The first string to be evaluated.
86+ /// - rhs: The second string to be evaluated.
87+ /// - Returns: A `StringPredicate` that performs a logical AND operation between two strings.
6388public func && ( lhs: String , rhs: String ) -> StringPredicate {
6489
6590 return . and( [ lhs, rhs] )
6691}
6792
6893/// Returns a `StringPredicate` that performs a logical AND operation between a string and a `StringPredicate`.
94+ /// - Parameters:
95+ /// - lhs: The string to be evaluated.
96+ /// - rhs: The `StringPredicate` to be evaluated.
97+ /// - Returns: A `StringPredicate` that performs a logical AND operation between a string and a `StringPredicate`.
6998public func && ( lhs: String , rhs: StringPredicate ) -> StringPredicate {
7099
71100 return . andPredicates( lhs, rhs)
72101}
73102
74103/// Returns a `StringPredicate` that performs a logical AND operation between a `StringPredicate` and a string.
104+ /// - Parameters:
105+ /// - lhs: The `StringPredicate` to be evaluated.
106+ /// - rhs: The string to be evaluated.
107+ /// - Returns: A `StringPredicate` that performs a logical AND operation between a `StringPredicate` and a string.
75108public func && ( lhs: StringPredicate , rhs: String ) -> StringPredicate {
76109
77110 return . andPredicates( rhs, lhs)
78111}
79112
80113/// Returns a `StringPredicate` that performs a logical AND operation between two `StringPredicate`s.
114+ /// - Parameters:
115+ /// - lhs: The first `StringPredicate` to be evaluated.
116+ /// - rhs: The second `StringPredicate` to be evaluated.
117+ /// - Returns: A `StringPredicate
81118public func && ( lhs: StringPredicate , rhs: StringPredicate ) -> StringPredicate {
82119
83120 return . andOnlyPredicates( [ rhs, lhs] )
84121}
85122
86123/// Returns a `StringPredicate` that performs a case-insensitive and diacritic-insensitive search for a given string.
124+ ///
125+ /// - Parameter value: The value to be evaluated.
126+ /// - Returns: A `StringPredicate` that performs a case-insensitive and diacritic-insensitive search for a given string.
87127public prefix func ~ ( value: String ) -> StringPredicate {
88128
89129 return . diacriticAndCaseInsensitive( value)
90130}
91131
132+ /// Returns a `StringPredicate` that negates another `StringPredicate`.
133+ ///
134+ /// - Parameter predicate: The predicate to be negated.
135+ /// - Returns: A `StringPredicate` that represents the negation of the given predicate.
136+ public prefix func ! ( predicate: StringPredicate ) -> StringPredicate {
137+
138+ return . negatablePredicate( predicate)
139+ }
140+
141+ /// Returns a `StringPredicate` that negates a given value.
142+ ///
143+ /// - Parameter value: The value to be negated.
144+ /// - Returns: A `StringPredicate` that represents the negation of the given value.
145+ public prefix func ! ( value: String ) -> StringPredicate {
146+
147+ return . negatable( value)
148+ }
92149
93150public extension String {
94151
0 commit comments