rust_string_utils/utils/
remove_delete.rs1
2pub fn remove(str: &String, remove: &String ) -> String {
13 str.replace(remove, "")
14}
15
16pub fn delete_white_space(str: &String) -> String {
26 str.replace(" ", "")
27}
28
29
30pub fn remove_ignore_case(str: &String, remove: &String) -> String {
41 str.to_lowercase().replace(&remove.to_lowercase(), "")
42}
43
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_remove() {
51 assert_eq!(remove(&"abcdef".to_string(), &"c".to_string()), "abdef");
52 assert_eq!(remove(&"abcdef".to_string(), &"z".to_string()), "abcdef");
53 assert_eq!(remove(&"abcdef".to_string(), &"".to_string()), "abcdef");
54 assert_eq!(remove(&"".to_string(), &"a".to_string()), "");
55 }
56
57 #[test]
58 fn test_delete_white_space() {
59 assert_eq!(delete_white_space(&"a b c".to_string()), "abc");
60 assert_eq!(delete_white_space(&"a b c".to_string()), "abc");
61 assert_eq!(delete_white_space(&" abc ".to_string()), "abc");
62 assert_eq!(delete_white_space(&"".to_string()), "");
63 }
64
65 #[test]
66 fn test_remove_ignore_case() {
67 assert_eq!(remove_ignore_case(&"abcdef".to_string(), &"C".to_string()), "abdef");
68 assert_eq!(remove_ignore_case(&"abcdef".to_string(), &"E".to_string()), "abcdf");
69 assert_eq!(remove_ignore_case(&"abcdef".to_string(), &"".to_string()), "abcdef");
70 assert_eq!(remove_ignore_case(&"".to_string(), &"A".to_string()), "");
71 }
72}