1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
pub trait MatchQuote {
fn match_quote(&self, line: &str) -> bool;
}
pub struct ExactMatch {
m: String,
}
impl ExactMatch {
pub fn new(m: String) -> Self {
ExactMatch { m }
}
}
impl MatchQuote for ExactMatch {
fn match_quote(&self, line: &str) -> bool {
self.m == line
}
}
pub struct PrefixMatch {
prefix: String,
}
impl MatchQuote for PrefixMatch {
fn match_quote(&self, line: &str) -> bool {
line.starts_with(&self.prefix)
}
}
impl PrefixMatch {
pub fn new(prefix: String) -> Self {
PrefixMatch { prefix }
}
}
pub struct TrimPrefixMatch {
prefix: String,
}
impl MatchQuote for TrimPrefixMatch {
fn match_quote(&self, line: &str) -> bool {
line.trim_start().starts_with(&self.prefix)
}
}
impl TrimPrefixMatch {
pub fn new(prefix: String) -> Self {
TrimPrefixMatch {
prefix: prefix.trim().to_string(),
}
}
}
pub struct TrimExactMatch {
m: String,
}
impl TrimExactMatch {
pub fn new(s: String) -> Self {
TrimExactMatch {
m: s.trim().to_string(),
}
}
}
impl MatchQuote for TrimExactMatch {
fn match_quote(&self, line: &str) -> bool {
self.m == line.trim()
}
}
pub struct KeywordMatch {
k: String,
}
impl KeywordMatch {
pub fn new(k: String) -> Self {
KeywordMatch { k }
}
}
impl MatchQuote for KeywordMatch {
fn match_quote(&self, line: &str) -> bool {
line.contains(&self.k)
}
}
pub struct ExcludeKeywordMatch {
e: String,
}
impl ExcludeKeywordMatch {
pub fn new(e: String) -> Self {
ExcludeKeywordMatch { e }
}
}
impl MatchQuote for ExcludeKeywordMatch {
fn match_quote(&self, line: &str) -> bool {
!line.contains(&self.e)
}
}