[][src]Crate censor

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 pick the replacement character
assert_eq!("JJJJ the letter J", censor.replace("fuck the letter J", 'J'));

// 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"))

Re-exports

pub use Censor::*;

Enums

Censor

A collection of words to censor

Statics

SEX_WORDS

Words related to sex

STANDARD_WORDS

Words that are profanities by most people's definition

ZEALOUS_WORDS

Words that are profanities only to the zealous