be a bit stricter... i guess i have settled on my level of strictness around names

This commit is contained in:
2025-08-09 18:12:47 +02:00
parent 8a6a35269c
commit 67d861325a
2 changed files with 16 additions and 10 deletions

View File

@@ -92,18 +92,25 @@ static BAD_WORDS: LazyLock<HashSet<String>> = 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;