1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use std::collections::HashMap;
use rubble_templates_core::evaluator::Function;
use rubble_templates_core::functions::SimpleFunction;
pub const EMPTY_STRING: &str = "";
pub fn string_functions() -> HashMap<String, Box<dyn Function>> {
let mut functions: HashMap<String, Box<dyn Function>> = HashMap::new();
functions.insert("concat".to_string(), SimpleFunction::new(concat_function));
functions.insert("trim".to_string(), SimpleFunction::new(trim_function));
functions.insert("$}".to_string(), SimpleFunction::new(right_brackets_function));
functions.insert("$quote".to_string(), SimpleFunction::new(quotes_function));
functions
}
pub fn concat_function(parameters: &[String]) -> String {
let mut result = EMPTY_STRING.to_string();
parameters.iter().for_each(|param| {
result.push_str(param);
});
result
}
pub fn trim_function(parameters: &[String]) -> String {
let mut result = EMPTY_STRING.to_string();
parameters.iter().for_each(|param| {
result.push_str(param.trim());
});
result
}
pub fn right_brackets_function(_: &[String]) -> String {
"}}".to_string()
}
pub fn quotes_function(_: &[String]) -> String {
"\"".to_string()
}