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

#117 in #filter

Download history 621/week @ 2024-06-19 544/week @ 2024-06-26 533/week @ 2024-07-03 491/week @ 2024-07-10 529/week @ 2024-07-17 635/week @ 2024-07-24 596/week @ 2024-07-31 684/week @ 2024-08-07 765/week @ 2024-08-14 621/week @ 2024-08-21 570/week @ 2024-08-28 539/week @ 2024-09-04 437/week @ 2024-09-11 418/week @ 2024-09-18 547/week @ 2024-09-25 260/week @ 2024-10-02

1,778 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