Skip to main content

Profanity

Struct Profanity 

Source
pub struct Profanity { /* private fields */ }
Expand description

better_profanity’s Profanity: a list of words to censor and how to match them.

Words are lowercased with Rust’s Unicode tables, which can differ from those of a given Python version for characters added to Unicode recently.

Implementations§

Source§

impl Profanity

Source

pub fn new() -> Self

The default word list, as Profanity().

Source

pub fn with_words<I, S>(words: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Profanity(words); an empty list loads the default words.

Source

pub fn load_censor_words<I, S, W>(&mut self, words: I, whitelist: &[W])
where I: IntoIterator<Item = S>, S: AsRef<str>, W: AsRef<str>,

load_censor_words(custom_words, whitelist_words): replaces the words with words, or with the default list if words is empty, leaving out those in whitelist.

Source

pub fn load_default_censor_words<W: AsRef<str>>(&mut self, whitelist: &[W])

load_censor_words(whitelist_words=whitelist): the default word list.

Source

pub fn load_censor_words_from_file<W: AsRef<str>>( &mut self, path: impl AsRef<Path>, whitelist: &[W], ) -> Result<()>

load_censor_words_from_file(path, whitelist_words): one word per line of a UTF-8 file. Unlike load_censor_words, an empty file leaves no words.

Source

pub fn add_censor_words<I, S>(&mut self, words: I)
where I: IntoIterator<Item = S>, S: AsRef<str>,

add_censor_words(words): adds words as they are, without lowercasing them or updating max_number_combinations.

Source

pub fn set_chars_mapping<I, V>(&mut self, mapping: I)
where I: IntoIterator<Item = (char, V)>, V: IntoIterator<Item = char>,

Replaces CHARS_MAPPING, which applies to words loaded or added afterwards.

Source

pub fn max_number_combinations(&self) -> usize

MAX_NUMBER_COMBINATIONS: how many following words are joined to the current one when looking for phrases. Loading words raises it to the largest number of separator characters in a word; it never decreases on its own.

Source

pub fn set_max_number_combinations(&mut self, n: usize)

Source

pub fn len(&self) -> usize

The number of words, as len(CENSOR_WORDSET).

Source

pub fn is_empty(&self) -> bool

Source

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

censor(text, censor_char): replaces each swear word with censor_char four times. With no words loaded, better_profanity loads the default list and keeps it; so does this method, in effect: later calls and changes see the default list.

Source

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

contains_profanity(text): whether censoring changes the text.

Trait Implementations§

Source§

impl Clone for Profanity

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Profanity

Source§

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

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

impl Default for Profanity

Source§

fn default() -> Self

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

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.