Expand description
A collection of words to censor
Variants
Standard
Standard swear words
For more information, see STANDARD_WORDS
Sex
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
sourceimpl Censor
impl Censor
sourcepub fn custom<I, W>(words: I) -> Selfwhere
I: IntoIterator<Item = W>,
W: Into<String>,
pub fn custom<I, W>(words: I) -> Selfwhere
I: IntoIterator<Item = W>,
W: Into<String>,
Create a Censor::Custom
sourcepub fn count(&self, text: &str) -> usize
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"));
sourcepub fn censor(&self, text: &str) -> String
pub fn censor(&self, text: &str) -> String
Replace censored words in the string with asterisks (*
s)
sourcepub fn replace(&self, text: &str, grawlix: &str) -> String
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
sourcepub fn replace_with_offsets(
&self,
text: &str,
grawlix: &str,
start_offset: usize,
end_offset: usize
) -> String
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
sourcepub fn bad_chars(
&self,
text: &str,
start_offset: usize,
end_offset: usize
) -> HashSet<usize>
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
Trait Implementations
sourceimpl AddAssign<Censor> for Censor
impl AddAssign<Censor> for Censor
sourcefn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moresourceimpl<S> AddAssign<S> for Censorwhere
S: Into<String>,
impl<S> AddAssign<S> for Censorwhere
S: Into<String>,
sourcefn add_assign(&mut self, other: S)
fn add_assign(&mut self, other: S)
+=
operation. Read moresourceimpl SubAssign<Censor> for Censor
impl SubAssign<Censor> for Censor
sourcefn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-=
operation. Read moresourceimpl<S> SubAssign<S> for Censorwhere
S: Into<String>,
impl<S> SubAssign<S> for Censorwhere
S: Into<String>,
sourcefn sub_assign(&mut self, other: S)
fn sub_assign(&mut self, other: S)
-=
operation. Read more