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

Indexes created Thu Nov 07 10:32:03 CST 2024