1 macro_rules! regex_new { 2 ($re:expr) => {{ 3 use regex::bytes::Regex; 4 Regex::new($re) 5 }}; 6 } 7 8 macro_rules! regex_set_new { 9 ($res:expr) => {{ 10 use regex::bytes::RegexSet; 11 RegexSet::new($res) 12 }}; 13 } 14 15 macro_rules! regex { 16 ($re:expr) => { 17 regex_new!($re).unwrap() 18 }; 19 } 20 21 macro_rules! regex_set { 22 ($res:expr) => { 23 regex_set_new!($res).unwrap() 24 }; 25 } 26 27 // Must come before other module definitions. 28 include!("macros_bytes.rs"); 29 include!("macros.rs"); 30 31 // A silly wrapper to make it possible to write and match raw bytes. 32 struct R<'a>(&'a [u8]); 33 impl<'a> R<'a> { as_bytes(&self) -> &'a [u8]34 fn as_bytes(&self) -> &'a [u8] { 35 self.0 36 } 37 } 38 39 // See: https://github.com/rust-lang/regex/issues/321 40 // 41 // These tests are here because they do not have the same behavior in every 42 // regex engine. 43 mat!(invalid_utf8_nfa1, r".", R(b"\xD4\xC2\x65\x2B\x0E\xFE"), Some((2, 3))); 44 mat!(invalid_utf8_nfa2, r"${2}ä", R(b"\xD4\xC2\x65\x2B\x0E\xFE"), None); 45 mat!( 46 invalid_utf8_nfa3, 47 r".", 48 R(b"\x0A\xDB\x82\x6E\x33\x01\xDD\x33\xCD"), 49 Some((1, 3)) 50 ); 51 mat!( 52 invalid_utf8_nfa4, 53 r"${2}ä", 54 R(b"\x0A\xDB\x82\x6E\x33\x01\xDD\x33\xCD"), 55 None 56 ); 57 58 mod api; 59 mod bytes; 60 mod crazy; 61 mod flags; 62 mod fowler; 63 mod multiline; 64 mod noparse; 65 mod regression; 66 mod replace; 67 mod set; 68 mod shortest_match; 69 mod suffix_reverse; 70 #[cfg(feature = "unicode")] 71 mod unicode; 72 #[cfg(feature = "unicode-perl")] 73 mod word_boundary; 74 #[cfg(feature = "unicode-perl")] 75 mod word_boundary_unicode; 76