dpp/util/
strings.rs

1pub fn convert_to_homograph_safe_chars(input: &str) -> String {
2    let mut replaced = String::with_capacity(input.len());
3
4    for c in input.to_lowercase().chars() {
5        match c {
6            'o' => replaced.push('0'),
7            'l' | 'i' => replaced.push('1'),
8            _ => replaced.push(c),
9        }
10    }
11
12    replaced
13}
14
15#[cfg(test)]
16mod tests {
17
18    use super::*;
19    mod convert_to_homograph_safe_chars {
20        use super::*;
21
22        #[test]
23        fn should_convert_0_and_l_to_o_and_l() {
24            let result = convert_to_homograph_safe_chars("A0boic0Dlelfl");
25
26            assert_eq!(result, "a0b01c0d1e1f1");
27        }
28    }
29}