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
pub fn starts_with(line: &str, words: &[&str]) -> bool {
    words.iter().any(|e| line.starts_with(e))
}

pub fn rcount_ends_with(mut line: &str, suffix: &[&str]) -> usize {
    if !ends_with(line, suffix) {
        return 0;
    }

    let mut r = true;
    let mut c = 0;

    while r {
        let res = suffix
            .iter()
            .enumerate()
            .filter_map(|(i, e)| {
                if line.ends_with(e) {
                    line = &line[..line.len() - e.len()];
                    return Some((i, true));
                }

                None
            })
            .count();
        c += res;
        r = res > 0;
    }

    c
}

pub fn count_starts_with(mut line: &str, suffix: &[&str]) -> usize {
    if !ends_with(line, suffix) {
        return 0;
    }

    let mut r = true;
    let mut c = 0;

    while r {
        let res = suffix
            .iter()
            .enumerate()
            .filter_map(|(i, e)| {
                if line.starts_with(e) {
                    line = &line[..line.len() - e.len()];
                    return Some((i, true));
                }

                None
            })
            .count();
        c += res;
        r = res > 0;
    }

    c
}

pub fn strip_starts_with(line: &str, words: &[&str]) -> usize {
    words.iter().any(|e| line.starts_with(e));
    0
}

pub fn ends_with(line: &str, words: &[&str]) -> bool {
    words.iter().any(|e| line.ends_with(e))
}

pub fn strip_ends_with(line: &str, words: &[&str]) -> usize {
    words.iter().any(|e| line.ends_with(e));
    0
}