Enum Censor

Source
pub enum Censor {
    Standard,
    Sex,
    Zealous,
    Custom(HashSet<String>),
}
Expand description

A collection of words to censor

Variants§

§

Standard

Standard swear words

For more information, see STANDARD_WORDS

§

Sex

Words related to sex

Not usually used by itself

For more information, see SEX_WORDS

§

Zealous

Words that are profanities only to the zealous

Not usually used by itself

For more information, see ZEALOUS_WORDS

§

Custom(HashSet<String>)

A custom set of words

Implementations§

Source§

impl Censor

Source

pub fn empty() -> Self

Create an empty Censor

Source

pub fn custom<I, W>(words: I) -> Self
where I: IntoIterator<Item = W>, W: Into<String>,

Create a Censor::Custom

Source

pub fn check(&self, text: &str) -> bool

Check if a string contains censored words

Source

pub fn count(&self, text: &str) -> usize

Count the number of censored words in a string

§Example
use censor::*;

let censor = Censor::Standard;

assert_eq!(0, censor.count("dog"));
assert_eq!(1, censor.count("motherfucker"));
assert_eq!(2, censor.count("bitch ass guy"));
Source

pub fn censor(&self, text: &str) -> String

Replace censored words in the string with asterisks (*s)

Source

pub fn replace(&self, text: &str, grawlix: &str) -> String

Replace censored words in the string with characters from a ‘grawlix’ string (#?!@$)

§Panics

Panics if the grawlix string is empty

Source

pub fn replace_with_offsets( &self, text: &str, grawlix: &str, start_offset: usize, end_offset: usize, ) -> String

Replace censored words in the string with characters from a ‘grawlix’ string (#?!@$)

Characters at indices within the given offsets from the start and end of words will not be censored

§Panics

Panics if the grawlix string is empty

Source

pub fn bad_chars( &self, text: &str, start_offset: usize, end_offset: usize, ) -> HashSet<usize>

Get a set of the indices of characters in the given string that are part of censored words

Source

pub fn set(&self) -> &HashSet<String>

Get a reference to the set used by the Censor

Source

pub fn list(&self) -> Iter<'_, String>

Get an iterator over all censored words

Source

pub fn find(&self, word: &str) -> Option<&str>

Find a censored word in the Censor. Applies character aliases

Source

pub fn contains(&self, word: &str) -> bool

Check if the Censor contains a word. Applies character aliases

Trait Implementations§

Source§

impl<S> Add<S> for Censor
where S: Into<String>,

Source§

type Output = Censor

The resulting type after applying the + operator.
Source§

fn add(self, other: S) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Censor

Source§

type Output = Censor

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<S> AddAssign<S> for Censor
where S: Into<String>,

Source§

fn add_assign(&mut self, other: S)

Performs the += operation. Read more
Source§

impl AddAssign for Censor

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl Clone for Censor

Source§

fn clone(&self) -> Censor

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Censor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Censor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Censor

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S> Sub<S> for Censor
where S: Into<String>,

Source§

type Output = Censor

The resulting type after applying the - operator.
Source§

fn sub(self, other: S) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Censor

Source§

type Output = Censor

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<S> SubAssign<S> for Censor
where S: Into<String>,

Source§

fn sub_assign(&mut self, other: S)

Performs the -= operation. Read more
Source§

impl SubAssign for Censor

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl Eq for Censor

Auto Trait Implementations§

§

impl Freeze for Censor

§

impl RefUnwindSafe for Censor

§

impl Send for Censor

§

impl Sync for Censor

§

impl Unpin for Censor

§

impl UnwindSafe for Censor

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.