4 releases (2 breaking)

0.3.0 Nov 16, 2022
0.2.0 Nov 24, 2020
0.1.1 Sep 24, 2019
0.1.0 Sep 24, 2019

#937 in Text processing

Download history 608/week @ 2024-07-19 611/week @ 2024-07-26 594/week @ 2024-08-02 730/week @ 2024-08-09 772/week @ 2024-08-16 532/week @ 2024-08-23 581/week @ 2024-08-30 571/week @ 2024-09-06 348/week @ 2024-09-13 494/week @ 2024-09-20 488/week @ 2024-09-27 413/week @ 2024-10-04 429/week @ 2024-10-11 581/week @ 2024-10-18 647/week @ 2024-10-25 657/week @ 2024-11-01

2,395 downloads per month
Used in 3 crates

MIT license

18KB
406 lines

Description

This is a simple profanity filter library for Rust.

For more information, check out the documentation.


lib.rs:

This crate implements a simple but powerful profanity filter.

While this filter can still be technically subverted, the goal is that by the time a profanity gets past the filter, it barely resembles the original word. This is done by subverting common profanity filter workarounds, such as inserting spaces or special characters in between letters (F_U_C_K) or using similar-looking characters in the place of others (SH!T).

Keep in mind though, that this filter is far from perfect. If people really want to swear, they can get through this filter.

Usage

The Censor enum is the main object used for censoring strings. It is essentially a set of words to be filtered out. The Standard variant contains words that most people consider to be swear words, and is meant to be a good baseline for a filter. More sets and individual words can be added with the + and += operators, and sets and words can be removed with the - and -= operators.

use censor::*;

let censor = Censor::Standard;

// Use `Censor::check` to check if a string contains a profanity
assert!(censor.check("fuck"));
assert!(censor.check("FUCK"));
assert!(censor.check("FuCk"));
assert!(censor.check("fμ¢κ"));
assert!(censor.check("f!u!c!k"));
assert!(censor.check("F_u c_K"));
assert!(censor.check("fuuuuuuuck"));

assert!(!censor.check("fluff truck"));
assert!(!censor.check("fukushima"));

// Use `Censor::censor` to censor a string with asterisks
assert_eq!("*_*_*_*_*", censor.censor("₱_û_$_$_¥"));
assert_eq!("**** that ****, dude", censor.censor("fuck that shit, dude"));
assert_eq!("******* yoouuu", censor.censor("fuuuuck yoouuu"));

// Use `Censor::replace` to replace censored words with any grawlix string
assert_eq!("What the !@#$?", censor.replace("What the fuck?", "!@#$%"));

// You can combine `Censor`s and add your own words
let censor = Standard + Zealous + Sex + "dong";

assert_eq!(
"Woops, I dropped my monster ******, that I use for my magnum ****",
censor.censor("Woops, I dropped my monster condom, that I use for my magnum dong")
);

// You can remove words from `Censor`s too
let censor = Standard - "ass";
assert!(!censor.check("I don't care if people say 'ass'"));

// Overlapping censored words are fully censored
let censor = Standard + Sex;
assert_eq!("**********", censor.censor("shititties"));
assert_eq!("*************", censor.censor("blowjoboobies"))

Dependencies

~47KB