rustrict

rustrict is a profanity filter for Rust.

When evaluated against the first 100,000 items of this list, it has 91.68% accuracy (89% positive accuracy, 92% negative accuracy), as of version 0.1.14. Much of the inaccuracy is due to differences of opinion of what is inappropriate.

Setup

toml rustrict = "0.1.14"

Usage

Strings (&str)

```rust use rustrict::CensorStr;

let censored: String = "hello crap".censor(); let inappropriate: bool = "f u c k".is_inappropriate();

assert_eq!(censored, "hello c*"); assert!(inappropriate); ```

Iterators (Iterator<Type = char>)

```rust use rustrict::CensorIter;

let censored: String = "hello crap".chars().censor().collect();

assert_eq!(censored, "hello c*") ```

Advanced

By constructing a Censor, one can avoid scanning text multiple times to get a censored String and/or answer multiple is queries. This also opens up more customization options (defaults are below).

```rust use rustrict::{Censor, Type};

let (censored, analysis) = Censor::fromstr("123 Crap") .withcensorthreshold(Type::INAPPROPRIATE) .withcensorfirstcharacterthreshold(Type::OFFENSIVE & Type::SEVERE) .withignorefalsepositives(false) .withcensorreplacement('*') .censorandanalyze();

assert_eq!(censored, "123 C*"); assert!(analysis.is(Type::INAPPROPRIATE)); assert!(analysis.isnt(Type::PROFANE & Type::SEVERE | Type::SEXUAL)); ```

Development

If you make an adjustment that would affect false positives, you will need to run false_positive_finder: 1. Run ./download.sh to get the required word lists. 2. Run cargo run --bin false_positive_finder --release --all-features

License

Licensed under either of

at your option.

Contribution

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.