use regex::Regex;
pub(crate) use std::fmt;
use std::ops::Add;
#[derive(Debug)]
pub struct HumanRegex(pub String);
impl HumanRegex {
pub fn to_regex(&self) -> Regex {
Regex::new(&*self.0).unwrap()
}
pub fn lazy(&self) -> HumanRegex {
HumanRegex(format!("{}?", &*self.0))
}
}
impl Add for HumanRegex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
HumanRegex(format!("{}{}", self.to_string(), rhs.to_string()))
}
}
impl fmt::Display for HumanRegex {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<HumanRegex> for String {
fn from(hr: HumanRegex) -> Self {
hr.to_string()
}
}