diff --git a/bad/bad-list.txt b/bad/bad-list.txt index 69a9859..397ca62 100644 --- a/bad/bad-list.txt +++ b/bad/bad-list.txt @@ -400,7 +400,6 @@ yaoi yellow showers yiffy zoophilia -🖕 analritter arsch arschficker diff --git a/src/main.rs b/src/main.rs index 1f955e1..e15358c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,18 +92,25 @@ static BAD_WORDS: LazyLock> = LazyLock::new(|| { }); fn contains_bad_word(text: &str) -> bool { - let cleaned_text: String = text.to_lowercase(); - - for (idx, a) in BAD_WORDS.iter().enumerate() { - if cleaned_text.trim() == a { - println!("Text contains {a} on line {idx}"); - } + // check parts of string, e.g. ABC_DEF checks both ABC and DEF + let cleaned_text = text.to_lowercase(); + if cleaned_text + .split(|c: char| !c.is_alphabetic()) + .any(|part| BAD_WORDS.iter().any(|bad| part == bad)) + { + return true; } - BAD_WORDS - .iter() - .any(|bad_word| cleaned_text.trim() == bad_word) + // check string as a whole, e.g. ABC_DEF checks for ABCDEF + let cleaned_text: String = text + .to_lowercase() + .chars() + .filter(|c| c.is_alphabetic()) + .collect(); + + BAD_WORDS.iter().any(|bad_word| &cleaned_text == bad_word) } + #[cfg(test)] mod tests { use super::contains_bad_word;