xref: /third_party/rust/crates/regex/bench/src/ffi/onig.rs (revision c67d6573)
1use onig;
2
3pub struct Regex(onig::Regex);
4
5unsafe impl Send for Regex {}
6
7impl Regex {
8    pub fn new(pattern: &str) -> Result<Self, onig::Error> {
9        onig::Regex::new(pattern).map(Regex)
10    }
11
12    pub fn is_match(&self, text: &str) -> bool {
13        // Gah. onig's is_match function is anchored, but find is not.
14        self.0
15            .search_with_options(
16                text,
17                0,
18                text.len(),
19                onig::SearchOptions::SEARCH_OPTION_NONE,
20                None,
21            )
22            .is_some()
23    }
24
25    pub fn find_iter<'r, 't>(
26        &'r self,
27        text: &'t str,
28    ) -> onig::FindMatches<'r, 't> {
29        self.0.find_iter(text)
30    }
31}
32