litcheck_filecheck/pattern/search/
aho_corasick.rs

1use litcheck::range::Range;
2
3use super::{DefaultSearcher, Input, Match};
4
5pub type AhoCorasickSearcher<'input> =
6    DefaultSearcher<aho_corasick::Input<'input>, aho_corasick::Match, aho_corasick::MatchError>;
7
8impl Match for aho_corasick::Match {
9    type PatternID = aho_corasick::PatternID;
10
11    fn is_empty(&self) -> bool {
12        aho_corasick::Match::is_empty(self)
13    }
14    fn pattern(&self) -> Self::PatternID {
15        aho_corasick::Match::pattern(self)
16    }
17    fn end(&self) -> usize {
18        aho_corasick::Match::end(self)
19    }
20    fn range(&self) -> Range<usize> {
21        aho_corasick::Match::range(self).into()
22    }
23}
24
25impl<'input> Input for aho_corasick::Input<'input> {
26    fn buffer(&self) -> &[u8] {
27        self.haystack()
28    }
29    fn anchored(&self) -> bool {
30        self.get_anchored().is_anchored()
31    }
32    fn range(&self) -> Range<usize> {
33        aho_corasick::Input::get_range(self).into()
34    }
35    fn start(&self) -> usize {
36        aho_corasick::Input::start(self)
37    }
38    fn set_start(&mut self, start: usize) {
39        aho_corasick::Input::set_start(self, start)
40    }
41    fn set_range(&mut self, range: Range<usize>) {
42        aho_corasick::Input::set_range(self, range)
43    }
44}