Crates.io | sensitive-rs |
lib.rs | sensitive-rs |
version | 0.2.2 |
source | src |
created_at | 2024-08-16 05:44:51.804837 |
updated_at | 2024-11-28 07:45:27.323933 |
description | Sensitive word search, verification, filtering and replacement. |
homepage | https://houseme.github.io/sensitive-rs |
repository | https://github.com/houseme/sensitive-rs |
max_upload_size | |
id | 1339951 |
size | 717,728 |
English 中文
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.
Add the following dependency to your Cargo.toml
:
[dependencies]
sensitive-rs = "0.1"
Here are some examples of how to use Sensitive-rs:
Here is an example of how to use the Filter struct
use sensitive_rs::Filter;
fn main() {
// 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 *****.");
}
Here is an example of how to use the Trie struct
use sensitive_rs::Trie;
fn main() {
// Create a new Trie filter
let filter = Trie::new();
filter.add_word("bad");
filter.add_word("worse");
// Find sensitive words
let result = filter.find_in("This is bad.");
assert_eq!(result, Some("bad".to_string()));
// Validate text
let result = filter.validate("This is worse.");
assert_eq!(result, Some("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 *****.");
}
For detailed documentation, please refer to Documentation.
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 or MIT license, shall be dual licensed as above, without any additional terms or conditions.