1pub mod exports {
2 pub use once_cell;
3 pub use regex;
4}
5
6#[macro_export]
7macro_rules! regex {
8 ($re:expr $(,)?) => {{
9 static RE: $crate::exports::once_cell::sync::OnceCell<$crate::exports::regex::Regex> =
10 $crate::exports::once_cell::sync::OnceCell::new();
11 RE.get_or_init(|| $crate::exports::regex::Regex::new($re).unwrap())
12 }};
13}
14
15#[macro_export]
16macro_rules! regex_multi_line {
17 ($re:expr $(,)?) => {{
18 static RE: $crate::exports::once_cell::sync::OnceCell<$crate::exports::regex::Regex> =
19 $crate::exports::once_cell::sync::OnceCell::new();
20 RE.get_or_init(|| {
21 $crate::exports::regex::RegexBuilder::new($re)
22 .multi_line(true)
23 .build()
24 .unwrap()
25 })
26 }};
27}
28
29#[macro_export]
30macro_rules! byte_regex {
31 ($re:expr $(,)?) => {{
32 static RE: $crate::exports::once_cell::sync::OnceCell<
33 $crate::exports::regex::bytes::Regex,
34 > = $crate::exports::once_cell::sync::OnceCell::new();
35 RE.get_or_init(|| $crate::exports::regex::bytes::Regex::new($re).unwrap())
36 }};
37}
38
39#[macro_export]
40macro_rules! byte_regex_multi_line {
41 ($re:expr $(,)?) => {{
42 static RE: $crate::exports::once_cell::sync::OnceCell<
43 $crate::exports::regex::bytes::Regex,
44 > = $crate::exports::once_cell::sync::OnceCell::new();
45 RE.get_or_init(|| {
46 $crate::exports::regex::bytes::RegexBuilder::new($re)
47 .multi_line(true)
48 .build()
49 .unwrap()
50 })
51 }};
52}
53
54#[cfg(test)]
55mod tests {
56 use regex::{bytes, Regex};
57
58 #[test]
59 fn regex_macro() {
60 let _: &Regex = regex!(r"\w?");
61 }
62
63 #[test]
64 fn regex_multi_line_macro() {
65 let _: &Regex = regex_multi_line!(r"\w?");
66 }
67
68 #[test]
69 fn byte_regex_macro() {
70 let _: &bytes::Regex = byte_regex!(r"\w?");
71 }
72
73 #[test]
74 fn byte_regex_multi_line_macro() {
75 let _: &bytes::Regex = byte_regex_multi_line!(r"\w?");
76 }
77}