azalea_block_macros/
utils.rs

1pub fn combinations_of<T: Clone>(items: &[Vec<T>]) -> Vec<Vec<T>> {
2    let mut combinations = Vec::new();
3    if items.is_empty() {
4        return combinations;
5    };
6    if items.len() == 1 {
7        for item in &items[0] {
8            combinations.push(vec![item.clone()]);
9        }
10        return combinations;
11    };
12
13    for i in 0..items[0].len() {
14        let item = &items[0][i];
15        for other_combinations in combinations_of(&items[1..]) {
16            let mut combination = vec![item.clone()];
17            combination.extend(other_combinations);
18            combinations.push(combination);
19        }
20    }
21
22    combinations
23}
24
25pub fn to_pascal_case(s: &str) -> String {
26    // we get the first item later so this is to make it impossible for that
27    // to error
28    if s.is_empty() {
29        return String::new();
30    }
31
32    let mut result = String::new();
33    let mut prev_was_underscore = true; // set to true by default so the first character is capitalized
34    if s.chars().next().unwrap().is_numeric() {
35        result.push('_');
36    }
37    for c in s.chars() {
38        if c == '_' {
39            prev_was_underscore = true;
40        } else if prev_was_underscore {
41            result.push(c.to_ascii_uppercase());
42            prev_was_underscore = false;
43        } else {
44            result.push(c);
45        }
46    }
47    result
48}