rust_censure/structs/
mod.rs1use std::collections::HashMap;
2use std::sync::RwLock;
3use once_cell::sync::Lazy;
4use thiserror::Error;
5
6#[derive(Debug)]
7pub struct LangData {
8 pub beep: &'static str,
9 pub beep_html: &'static str,
10
11 pub foul_data: &'static HashMap<&'static str, Vec<&'static str>>,
12 pub foul_core: &'static HashMap<&'static str, &'static str>,
13 pub excludes_data: &'static HashMap<&'static str, Vec<&'static str>>,
14 pub excludes_core: &'static HashMap<&'static str, &'static str>,
15 pub bad_semi_phrases: &'static Vec<&'static str>,
16 pub bad_phrases: &'static Vec<&'static str>,
17 pub trans_tab: &'static HashMap<char, char>,
18}
19
20impl LangData {
21 pub fn get_beep(&self) -> &str {
22 self.beep
23 }
24
25 pub fn set_beep(&mut self, val: &'static str) -> &str {
26 self.beep = val;
27 self.beep
28 }
29
30 pub fn get_beep_html(&self) -> &str {
31 self.beep_html
32 }
33
34 pub fn set_beep_html(&mut self, val: &'static str) -> &str {
35 self.beep_html = val;
36 self.beep_html
37 }
38}
39
40#[derive(Clone, Copy, Debug)]
41pub enum CensorLang { Ru, En }
42
43pub struct Censor {
44 pub lang: CensorLang,
45 pub data: LangData,
46 pub re_cache: Lazy<RwLock<HashMap<String, fancy_regex::Regex>>>
47}
48
49#[derive(Debug, Error)]
50pub enum CensorError {
51 #[error("unsupported language: {0}")]
52 UnsupportedLang(String),
53}
54
55#[derive(Debug)]
56pub struct WordInfo {
57 pub is_good: bool,
58 pub word: String,
59 pub accuse: Vec<String>,
60 pub excuse: Vec<String>,
61}
62impl WordInfo {
63 pub fn new(word: String) -> Self {
64 Self { is_good: true, word, accuse: vec![], excuse: vec![] }
65 }
66}
67
68#[derive(Debug)]
69pub struct CleanLineResult {
70 pub line: String,
71 pub bad_words_count: usize,
72 pub bad_phrases_count: usize,
73 pub detected_bad_words: Vec<String>,
74 pub detected_patterns: Vec<String>,
75}
76
77#[derive(Debug)]
78pub struct CleanHtmlResult {
79 pub line: String,
80 pub bad_words_count: usize,
81}