1 use onig; 2 3 pub struct Regex(onig::Regex); 4 5 unsafe impl Send for Regex {} 6 7 impl Regex { new(pattern: &str) -> Result<Self, onig::Error>8 pub fn new(pattern: &str) -> Result<Self, onig::Error> { 9 onig::Regex::new(pattern).map(Regex) 10 } 11 is_match(&self, text: &str) -> bool12 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 find_iter<'r, 't>( &'r self, text: &'t str, ) -> onig::FindMatches<'r, 't>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