@@ -37,9 +37,9 @@ impl Function for Contains {
3737 let mut found = false ;
3838
3939 let ( string_to_find, number_to_find) = if let Some ( string) = args[ 1 ] . as_str ( ) {
40- ( string. to_string ( ) , 0 )
40+ ( Some ( string. to_string ( ) ) , None )
4141 } else if let Some ( number) = args[ 1 ] . as_i64 ( ) {
42- ( number . to_string ( ) , number)
42+ ( None , Some ( number) )
4343 } else {
4444 return Err ( DscError :: Parser ( t ! ( "functions.contains.invalidItemToFind" ) . to_string ( ) ) ) ;
4545 } ;
@@ -48,14 +48,18 @@ impl Function for Contains {
4848 if let Some ( array) = args[ 0 ] . as_array ( ) {
4949 for item in array {
5050 if let Some ( item_str) = item. as_str ( ) {
51- if item_str == string_to_find {
52- found = true ;
53- break ;
51+ if let Some ( string) = & string_to_find {
52+ if item_str == string {
53+ found = true ;
54+ break ;
55+ }
5456 }
5557 } else if let Some ( item_num) = item. as_i64 ( ) {
56- if item_num == number_to_find {
57- found = true ;
58- break ;
58+ if let Some ( number) = number_to_find {
59+ if item_num == number {
60+ found = true ;
61+ break ;
62+ }
5963 }
6064 }
6165 }
@@ -66,18 +70,27 @@ impl Function for Contains {
6670 if let Some ( object) = args[ 0 ] . as_object ( ) {
6771 // see if key exists
6872 for key in object. keys ( ) {
69- if key == & string_to_find {
70- found = true ;
71- break ;
73+ if let Some ( string) = & string_to_find {
74+ if key == string {
75+ found = true ;
76+ break ;
77+ }
78+ } else if let Some ( number) = number_to_find {
79+ if key == & number. to_string ( ) {
80+ found = true ;
81+ break ;
82+ }
7283 }
7384 }
7485 return Ok ( Value :: Bool ( found) ) ;
7586 }
7687
7788 // for string, we check if the string contains the substring or number
7889 if let Some ( str) = args[ 0 ] . as_str ( ) {
79- if str. contains ( & string_to_find) {
80- found = true ;
90+ if let Some ( string) = & string_to_find {
91+ found = str. contains ( string) ;
92+ } else if let Some ( number) = number_to_find {
93+ found = str. contains ( & number. to_string ( ) ) ;
8194 }
8295 return Ok ( Value :: Bool ( found) ) ;
8396 }
0 commit comments