Crates.io | word_filter |
lib.rs | word_filter |
version | 0.8.1 |
source | src |
created_at | 2021-01-28 01:47:34.956957 |
updated_at | 2021-08-29 21:31:51.13761 |
description | A Word Filter for filtering text. |
homepage | |
repository | https://github.com/Anders429/word_filter |
max_upload_size | |
id | 347523 |
size | 111,368 |
A Word Filter for filtering text.
A Word Filter is a system for identifying and censoring specific words or phrases in strings. Common usage includes censoring vulgar or profane language and preventing spam or vandelism in user-provided content.
The Word Filter implementation provided here allows for advanced filtering functionality, including:
A Word Filter is useful for checking and censoring user-generated text in chat applications, online games, and many other contexts.
The most common usage for this crate is to generate a WordFilter
at compile time using a
build script using the
codegen
module. See the following simple
example and the documentation for further details.
For example, a simple WordFilter
can be generated by the following.
First, add the word_filter
crate to both the Cargo.toml
[dependencies]
and
[build-dependencies]
lists.
[dependencies]
word_filter = "0.7.0"
[build-dependencies]
word_filter = "0.7.0"
Next, generate the WordFilter
in the build.rs
file.
use std::{
env,
fs::File,
io::{BufWriter, Write},
path::Path,
};
use word_filter::codegen::{Visibility, WordFilterGenerator};
fn main() {
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
writeln!(
&mut file,
"{}",
WordFilterGenerator::new()
.visibility(Visibility::Pub)
.word("foo")
.generate("FILTER")
);
}
And finally, include the generated code in the lib.rs
file.
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
assert!(FILTER.censor("Should censor foo."), "Should censor ***.");
This crate is guaranteed to compile on stable rustc 1.51.0
and up.
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.