use crate::operation::{Operation, OperationControl, MATCHES_ZLS_AT_START};
use crate::re_flags::ReFlags;
use crate::re_matcher::ReMatcher;
#[derive(Debug, Clone)]
pub(crate) struct Bol;
impl OperationControl for Bol {
fn get_match_length(&self) -> Option<usize> {
Some(0)
}
fn matches_empty_string(&self) -> u32 {
MATCHES_ZLS_AT_START
}
fn optimize(self, _flags: &ReFlags) -> Operation {
Operation::from(self)
}
fn matches_iter<'a>(
&self,
matcher: &'a ReMatcher,
position: usize,
) -> Box<dyn Iterator<Item = usize> + 'a> {
if position != 0 {
if matcher.program.flags.is_multi_line() {
if matcher.is_new_line(position - 1) && position < matcher.search.len() {
return Box::new(std::iter::once(position));
}
}
return Box::new(std::iter::empty());
}
Box::new(std::iter::once(position))
}
}