openzeppelin_monitor/utils/
expression.rs1pub fn split_expression(expr: &str) -> Option<(&str, &str, &str)> {
9 let mut in_quotes = false;
11 let mut operator_start = None;
12 let mut operator_end = None;
13
14 let operators = [
15 "==",
16 "!=",
17 ">=",
18 "<=",
19 ">",
20 "<",
21 "contains",
22 "starts_with",
23 "ends_with",
24 ];
25
26 for (i, c) in expr.char_indices() {
28 if c == '\'' || c == '"' {
29 in_quotes = !in_quotes;
30 continue;
31 }
32
33 if !in_quotes {
34 for op in operators {
36 if expr[i..].starts_with(op) {
37 operator_start = Some(i);
38 operator_end = Some(i + op.len());
39 break;
40 }
41 }
42 if operator_start.is_some() {
43 break;
44 }
45 }
46 }
47
48 if let (Some(op_start), Some(op_end)) = (operator_start, operator_end) {
50 let left = expr[..op_start].trim();
51 let operator = expr[op_start..op_end].trim();
52 let right = expr[op_end..].trim();
53
54 let right = right.trim_matches(|c| c == '\'' || c == '"');
56
57 Some((left, operator, right))
58 } else {
59 None
60 }
61}