@@ -37,9 +37,9 @@ impl Function for Contains {
37
37
let mut found = false ;
38
38
39
39
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 )
41
41
} else if let Some ( number) = args[ 1 ] . as_i64 ( ) {
42
- ( number . to_string ( ) , number)
42
+ ( None , Some ( number) )
43
43
} else {
44
44
return Err ( DscError :: Parser ( t ! ( "functions.contains.invalidItemToFind" ) . to_string ( ) ) ) ;
45
45
} ;
@@ -48,14 +48,18 @@ impl Function for Contains {
48
48
if let Some ( array) = args[ 0 ] . as_array ( ) {
49
49
for item in array {
50
50
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
+ }
54
56
}
55
57
} 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
+ }
59
63
}
60
64
}
61
65
}
@@ -66,18 +70,27 @@ impl Function for Contains {
66
70
if let Some ( object) = args[ 0 ] . as_object ( ) {
67
71
// see if key exists
68
72
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
+ }
72
83
}
73
84
}
74
85
return Ok ( Value :: Bool ( found) ) ;
75
86
}
76
87
77
88
// for string, we check if the string contains the substring or number
78
89
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 ( ) ) ;
81
94
}
82
95
return Ok ( Value :: Bool ( found) ) ;
83
96
}
0 commit comments