undup/
lib.rs

1/// Remove duplicate characters in a string
2pub fn undup_chars(input: &str, chars: Vec<char>) -> String {
3    let mut output = String::new();
4    let mut previous_char = '\0';
5
6    for c in input.chars() {
7        if !(c == previous_char && chars.contains(&c)) {
8            output.push(c);
9        }
10 
11        previous_char = c;
12    }
13
14    output
15}
16
17#[test]
18fn test_undup_chars() {
19    let input = "The   Quick     Brown Fox       Jumps  Over The    Lazy Dog.........";
20    let output = undup_chars(&input, vec![' ', '.']);
21    assert_eq!("The Quick Brown Fox Jumps Over The Lazy Dog.", output);
22}