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
impl Profanity
Sourcepub fn with_words<I, S>(words: I) -> Self
pub fn with_words<I, S>(words: I) -> Self
Profanity(words); an empty list loads the default words.
Sourcepub fn load_censor_words<I, S, W>(&mut self, words: I, whitelist: &[W])
pub fn load_censor_words<I, S, W>(&mut self, words: I, whitelist: &[W])
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.
Sourcepub fn load_default_censor_words<W: AsRef<str>>(&mut self, whitelist: &[W])
pub fn load_default_censor_words<W: AsRef<str>>(&mut self, whitelist: &[W])
load_censor_words(whitelist_words=whitelist): the default word list.
Sourcepub fn load_censor_words_from_file<W: AsRef<str>>(
&mut self,
path: impl AsRef<Path>,
whitelist: &[W],
) -> Result<()>
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.
Sourcepub fn add_censor_words<I, S>(&mut self, words: I)
pub fn add_censor_words<I, S>(&mut self, words: I)
add_censor_words(words): adds words as they are, without lowercasing them or
updating max_number_combinations.
Sourcepub fn set_chars_mapping<I, V>(&mut self, mapping: I)
pub fn set_chars_mapping<I, V>(&mut self, mapping: I)
Replaces CHARS_MAPPING, which applies to words loaded or added afterwards.
Sourcepub fn max_number_combinations(&self) -> usize
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.
pub fn set_max_number_combinations(&mut self, n: usize)
pub fn is_empty(&self) -> bool
Sourcepub fn censor(&self, text: &str, censor_char: &str) -> String
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.
Sourcepub fn contains_profanity(&self, text: &str) -> bool
pub fn contains_profanity(&self, text: &str) -> bool
contains_profanity(text): whether censoring changes the text.