@@ -10,6 +10,7 @@ infix operator || : LogicalDisjunctionPrecedence
1010infix operator && : LogicalConjunctionPrecedence
1111prefix operator ~
1212prefix operator =~
13+ prefix operator !
1314
1415/// An enum representing a string search predicate.
1516public indirect enum StringPredicate {
@@ -38,67 +39,131 @@ public indirect enum StringPredicate {
3839 /// Represents a regular expression pattern that can be used to match a string using NSRegularExpression.
3940 /// - Note: The String value should be a valid regular expression pattern.
4041 case regexp( String )
42+
43+ /// Represents a negatable search predicate for a given string.
44+ case negatable( String )
45+
46+ /// Represents a negatable search predicate for a given `StringPredicate`.
47+ case negatablePredicate( StringPredicate )
4148}
4249
4350/// Returns a `StringPredicate` that performs a logical OR operation between two strings.
51+ /// - Parameters:
52+ /// - lhs: The first string to be evaluated.
53+ /// - rhs: The second string to be evaluated.
54+ /// - Returns: A `StringPredicate` that performs a logical OR operation between two strings.
4455public func || ( lhs: String , rhs: String ) -> StringPredicate {
4556
4657 return . or( [ lhs, rhs] )
4758}
4859
4960/// Returns a `StringPredicate` that performs a logical OR operation between a string and a `StringPredicate`.
61+ /// - Parameters:
62+ /// - lhs: The string to be evaluated.
63+ /// - rhs: The `StringPredicate` to be evaluated.
64+ /// - Returns: A `StringPredicate` that performs a logical OR operation between a string and a `StringPredicate`.
5065public func || ( lhs: String , rhs: StringPredicate ) -> StringPredicate {
5166
5267 return . orPredicates( lhs, rhs)
5368}
5469
5570/// Returns a `StringPredicate` that performs a logical OR operation between a `StringPredicate` and a string.
71+ /// - Parameters:
72+ /// - lhs: The `StringPredicate` to be evaluated.
73+ /// - rhs: The string to be evaluated.
74+ /// - Returns: A `StringPredicate` that performs a logical OR operation between a `StringPredicate` and a string.
5675public func || ( lhs: StringPredicate , rhs: String ) -> StringPredicate {
5776
5877 return . orPredicates( rhs, lhs)
5978}
6079
6180/// Returns a `StringPredicate` that performs a logical OR operation between two `StringPredicate`s.
81+ /// - Parameters:
82+ /// - lhs: The first `StringPredicate` to be evaluated.
83+ /// - rhs: The second `StringPredicate` to be evaluated.
84+ /// - Returns: A `StringPredicate` that performs a logical OR operation between two `StringPredicate`s.
6285public func || ( lhs: StringPredicate , rhs: StringPredicate ) -> StringPredicate {
6386
6487 return . orOnlyPredicates( [ rhs, lhs] )
6588}
6689
6790/// Returns a `StringPredicate` that performs a logical AND operation between two strings.
91+ /// - Parameters:
92+ /// - lhs: The first string to be evaluated.
93+ /// - rhs: The second string to be evaluated.
94+ /// - Returns: A `StringPredicate` that performs a logical AND operation between two strings.
6895public func && ( lhs: String , rhs: String ) -> StringPredicate {
6996
7097 return . and( [ lhs, rhs] )
7198}
7299
73100/// Returns a `StringPredicate` that performs a logical AND operation between a string and a `StringPredicate`.
101+ /// - Parameters:
102+ /// - lhs: The string to be evaluated.
103+ /// - rhs: The `StringPredicate` to be evaluated.
104+ /// - Returns: A `StringPredicate` that performs a logical AND operation between a string and a `StringPredicate`.
74105public func && ( lhs: String , rhs: StringPredicate ) -> StringPredicate {
75106
76107 return . andPredicates( lhs, rhs)
77108}
78109
79110/// Returns a `StringPredicate` that performs a logical AND operation between a `StringPredicate` and a string.
111+ /// - Parameters:
112+ /// - lhs: The `StringPredicate` to be evaluated.
113+ /// - rhs: The string to be evaluated.
114+ /// - Returns: A `StringPredicate` that performs a logical AND operation between a `StringPredicate` and a string.
80115public func && ( lhs: StringPredicate , rhs: String ) -> StringPredicate {
81116
82117 return . andPredicates( rhs, lhs)
83118}
84119
85120/// Returns a `StringPredicate` that performs a logical AND operation between two `StringPredicate`s.
121+ /// - Parameters:
122+ /// - lhs: The first `StringPredicate` to be evaluated.
123+ /// - rhs: The second `StringPredicate` to be evaluated.
124+ /// - Returns: A `StringPredicate
86125public func && ( lhs: StringPredicate , rhs: StringPredicate ) -> StringPredicate {
87126
88127 return . andOnlyPredicates( [ rhs, lhs] )
89128}
90129
91130/// Returns a `StringPredicate` that performs a case-insensitive and diacritic-insensitive search for a given string.
131+ ///
132+ /// - Parameter value: The value to be evaluated.
133+ /// - Returns: A `StringPredicate` that performs a case-insensitive and diacritic-insensitive search for a given string.
92134public prefix func ~ ( value: String ) -> StringPredicate {
93135
94136 return . diacriticAndCaseInsensitive( value)
95137}
96138
139+ /// Returns a `StringPredicate` that performs a regular expression pattern that can be used to match a string using NSRegularExpression.
140+ ///
141+ /// - Parameter value: The regular expression pattern as a string value.
142+ /// - Returns: A `StringPredicate` that can be used to perform regular expression pattern matching.
97143public prefix func =~ ( value: String ) -> StringPredicate {
98144
99145 return . regexp( value)
100146}
101147
148+
149+ /// Returns a `StringPredicate` that negates another `StringPredicate`.
150+ ///
151+ /// - Parameter predicate: The predicate to be negated.
152+ /// - Returns: A `StringPredicate` that represents the negation of the given predicate.
153+ public prefix func ! ( predicate: StringPredicate ) -> StringPredicate {
154+
155+ return . negatablePredicate( predicate)
156+ }
157+
158+ /// Returns a `StringPredicate` that negates a given value.
159+ ///
160+ /// - Parameter value: The value to be negated.
161+ /// - Returns: A `StringPredicate` that represents the negation of the given value.
162+ public prefix func ! ( value: String ) -> StringPredicate {
163+
164+ return . negatable( value)
165+ }
166+
102167public extension String {
103168
104169 /// Returns a Boolean value indicating whether the string contains the given `StringPredicate`.
0 commit comments