Crate sensitive_rs

Source
Expand description

§Sensitive-rs

sensitive-rs is a Rust library for finding, validating, filtering, and replacing sensitive words. It provides efficient algorithms to handle sensitive words, suitable for various application scenarios.

§Features

  • Find: Locate all sensitive words in a text.
  • Validate: Check if a text contains any sensitive words.
  • Filter: Remove sensitive words from a text.
  • Replace: Replace sensitive words in a text with specified characters.

§Installation

Add the following dependency to your Cargo.toml:

[dependencies]
sensitive-rs = "0.1"

§Quick Start

use sensitive_rs::Filter;

// Create a new Filter
let mut filter = Filter::new();
filter.add_word("bad");
filter.add_word("worse");

// Find sensitive words
let result = filter.find_in("This is bad.");
assert_eq!(result, (true, "bad".to_string()));

// Validate text
let result = filter.validate("This is worse.");
assert_eq!(result, (true, "worse".to_string()));

// Filter sensitive words
let filtered_text = filter.filter("This is bad and worse.");
assert_eq!(filtered_text, "This is  and .");

// Replace sensitive words
let replaced_text = filter.replace("This is bad and worse.", '*');
assert_eq!(replaced_text, "This is *** and *****.");

§Documentation

For detailed documentation, please refer to Documentation.

§License

Licensed under either of

Structs§

  • Sensitive word filter. It provides efficient algorithms to handle sensitive words, suitable for various application scenarios.
  • Trie data structure. It is a tree data structure used for efficient retrieval of a key in a large dataset.
  • Trie node. It is a tree data structure used for efficient retrieval of a key in a large dataset.