pub struct RegexWrap(&'static str, ::std::sync::OnceLock<::regex::Regex>);
impl RegexWrap {
#[must_use]
pub const fn new(re: &'static str) -> Self {
Self(re, ::std::sync::OnceLock::<::regex::Regex>::new())
}
}
impl ::std::ops::Deref for RegexWrap {
type Target = ::regex::Regex;
fn deref(&self) -> &Self::Target {
self.1.get_or_init(|| ::regex::Regex::new(self.0).unwrap())
}
}
macro_rules! decl_regex {
($($name:ident : $re:literal; )*) => {
$(
static $name: $crate::utils::RegexWrap = $crate::utils::RegexWrap::new($re);
)*
};
}
macro_rules! werr(
($($arg:tt)*) => ({
use std::io::{Write, stderr};
write!(&mut stderr(), $($arg)*).unwrap();
})
);
#[inline]
#[must_use]
pub fn cap_or_empty<'t>(caps: ®ex::Captures<'t>, name: &str) -> &'t str {
caps.name(name).map_or("", |m| m.as_str())
}