be a bit stricter... i guess i have settled on my level of strictness around names
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -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;
|
||||
|
Reference in New Issue
Block a user