use re_trait::{RegularExpression, Slot};
#[doc(hidden)]
pub struct Plugin {
#[doc(hidden)]
pub original: &'static str,
#[doc(hidden)]
pub names: &'static &'static [Option<&'static str>],
#[doc(hidden)]
pub groups: &'static &'static [(&'static str, usize)],
#[doc(hidden)]
pub prog: fn(&mut [Slot], &str, usize) -> bool,
}
impl Copy for Plugin {}
impl Clone for Plugin {
fn clone(&self) -> Plugin {
*self
}
}
impl RegularExpression for Plugin {
type Text = str;
fn slots_len(&self) -> usize {
self.names.len() * 2
}
fn next_after_empty(&self, text: &str, i: usize) -> usize {
i + text[i..].chars().next().unwrap().len_utf8()
}
fn shortest_match_at(&self, text: &str, start: usize) -> Option<usize> {
self.find_at(text, start).map(|(_, e)| e)
}
fn is_match_at(&self, text: &str, start: usize) -> bool {
(self.prog)(&mut [], text, start)
}
fn find_at(&self, text: &str, start: usize) -> Option<(usize, usize)> {
let mut slots = [None, None];
self.captures_at(&mut slots, text, start)
}
fn captures_at<'t>(
&self,
slots: &mut [Slot],
text: &'t str,
start: usize,
) -> Option<(usize, usize)> {
(self.prog)(slots, text, start);
match (slots[0], slots[1]) {
(Some(s), Some(e)) => Some((s, e)),
_ => None,
}
}
}