@@ -11,7 +11,9 @@ pub enum Expression {
1111 Equals ( Value ) ,
1212 NotEquals ( Value ) ,
1313 StartsWith ( Value ) ,
14+ NotStartsWith ( Value ) ,
1415 EndsWith ( Value ) ,
16+ NotEndsWith ( Value ) ,
1517 Contains ( Value ) ,
1618 NotContains ( Value ) ,
1719 Exists ,
@@ -32,10 +34,18 @@ impl Expression {
3234 Expression :: StartsWith ( Value :: new ( value, sensitive) )
3335 }
3436
37+ pub fn not_starts_with ( value : impl AsRef < str > , sensitive : bool ) -> Self {
38+ Expression :: NotStartsWith ( Value :: new ( value, sensitive) )
39+ }
40+
3541 pub fn ends_with ( value : impl AsRef < str > , sensitive : bool ) -> Self {
3642 Expression :: EndsWith ( Value :: new ( value, sensitive) )
3743 }
3844
45+ pub fn not_ends_with ( value : impl AsRef < str > , sensitive : bool ) -> Self {
46+ Expression :: NotEndsWith ( Value :: new ( value, sensitive) )
47+ }
48+
3949 pub fn contains ( value : impl AsRef < str > , sensitive : bool ) -> Self {
4050 Expression :: Contains ( Value :: new ( value, sensitive) )
4151 }
@@ -50,12 +60,22 @@ impl Expression {
5060 . map_err ( Error :: new)
5161 }
5262
63+ pub fn exists ( ) -> Self {
64+ Self :: Exists
65+ }
66+
67+ pub fn not_exists ( ) -> Self {
68+ Self :: NotExists
69+ }
70+
5371 pub fn matches ( & self , text : Option < & str > ) -> bool {
5472 match self {
5573 Expression :: Equals ( value) => value. equals ( text) ,
5674 Expression :: NotEquals ( value) => value. not_equals ( text) ,
5775 Expression :: StartsWith ( value) => value. starts_with ( text) ,
76+ Expression :: NotStartsWith ( value) => value. not_starts_with ( text) ,
5877 Expression :: EndsWith ( value) => value. ends_with ( text) ,
78+ Expression :: NotEndsWith ( value) => value. not_ends_with ( text) ,
5979 Expression :: Contains ( value) => value. contains ( text) ,
6080 Expression :: NotContains ( value) => value. not_contains ( text) ,
6181 Expression :: Exists => text. is_some ( ) ,
@@ -83,10 +103,18 @@ impl Display for Expression {
83103 f. write_str ( "StartsWith" ) ?;
84104 <Value as Display >:: fmt ( value, f)
85105 }
106+ Expression :: NotStartsWith ( value) => {
107+ f. write_str ( "NotStartWith" ) ?;
108+ <Value as Display >:: fmt ( value, f)
109+ }
86110 Expression :: EndsWith ( value) => {
87111 f. write_str ( "EndsWith" ) ?;
88112 <Value as Display >:: fmt ( value, f)
89113 }
114+ Expression :: NotEndsWith ( value) => {
115+ f. write_str ( "NotEndsWith" ) ?;
116+ <Value as Display >:: fmt ( value, f)
117+ }
90118 Expression :: Contains ( value) => {
91119 f. write_str ( "Contains" ) ?;
92120 <Value as Display >:: fmt ( value, f)
@@ -121,8 +149,12 @@ impl FromStr for Expression {
121149 "?NotEquals" => Ok ( Expression :: not_equals ( value, false ) ) ,
122150 "StartsWith" => Ok ( Expression :: starts_with ( value, true ) ) ,
123151 "?StartsWith" => Ok ( Expression :: starts_with ( value, false ) ) ,
152+ "NotStartsWith" => Ok ( Expression :: not_starts_with ( value, true ) ) ,
153+ "?NotStartsWith" => Ok ( Expression :: not_starts_with ( value, false ) ) ,
124154 "EndsWith" => Ok ( Expression :: ends_with ( value, true ) ) ,
125155 "?EndsWith" => Ok ( Expression :: ends_with ( value, false ) ) ,
156+ "NotEndsWith" => Ok ( Expression :: not_ends_with ( value, true ) ) ,
157+ "?NotEndsWith" => Ok ( Expression :: not_ends_with ( value, false ) ) ,
126158 "Contains" => Ok ( Expression :: contains ( value, true ) ) ,
127159 "?Contains" => Ok ( Expression :: contains ( value, false ) ) ,
128160 "NotContains" => Ok ( Expression :: not_contains ( value, true ) ) ,
@@ -200,67 +232,57 @@ impl Value {
200232 }
201233
202234 pub fn not_equals ( & self , value : Option < & str > ) -> bool {
203- match value {
204- Some ( value) => {
205- if self . sensitive {
206- self . raw . as_ref ( ) != value
207- } else {
208- !self . raw . as_ref ( ) . eq_ignore_ascii_case ( value)
209- }
210- }
211- None => true ,
212- }
235+ !self . equals ( value)
213236 }
214237
215238 pub fn starts_with ( & self , value : Option < & str > ) -> bool {
216239 match value {
217240 Some ( value) => {
218241 if self . sensitive {
219- self . raw . starts_with ( value )
242+ value . starts_with ( self . raw . as_ref ( ) )
220243 } else {
221- self . raw . starts_with ( & value . to_lowercase ( ) )
244+ value . to_lowercase ( ) . starts_with ( self . raw . as_ref ( ) )
222245 }
223246 }
224247 None => false ,
225248 }
226249 }
227250
251+ pub fn not_starts_with ( & self , value : Option < & str > ) -> bool {
252+ !self . starts_with ( value)
253+ }
254+
228255 pub fn ends_with ( & self , value : Option < & str > ) -> bool {
229256 match value {
230257 Some ( value) => {
231258 if self . sensitive {
232- self . raw . ends_with ( value )
259+ value . ends_with ( self . raw . as_ref ( ) )
233260 } else {
234- self . raw . ends_with ( & value . to_lowercase ( ) )
261+ value . to_lowercase ( ) . ends_with ( self . raw . as_ref ( ) )
235262 }
236263 }
237264 None => false ,
238265 }
239266 }
240267
268+ pub fn not_ends_with ( & self , value : Option < & str > ) -> bool {
269+ !self . ends_with ( value)
270+ }
271+
241272 pub fn contains ( & self , value : Option < & str > ) -> bool {
242273 match value {
243274 Some ( value) => {
244275 if self . sensitive {
245- self . raw . contains ( value )
276+ value . contains ( self . raw . as_ref ( ) )
246277 } else {
247- self . raw . contains ( & value . to_lowercase ( ) )
278+ value . to_lowercase ( ) . contains ( self . raw . as_ref ( ) )
248279 }
249280 }
250281 None => false ,
251282 }
252283 }
253284
254285 pub fn not_contains ( & self , value : Option < & str > ) -> bool {
255- match value {
256- Some ( value) => {
257- if self . sensitive {
258- !self . raw . contains ( value)
259- } else {
260- !self . raw . contains ( & value. to_lowercase ( ) )
261- }
262- }
263- None => true ,
264- }
286+ !self . contains ( value)
265287 }
266288}
0 commit comments