use crate::match_result::MatchResult;
use crate::matcher::Matcher;
pub struct AllEndOfLineMatcher {
prev_char: u8,
}
impl AllEndOfLineMatcher {
pub fn new() -> Self {
Self { prev_char: 0 }
}
}
impl Matcher for AllEndOfLineMatcher {
fn sequel(&mut self, el_buf: u8, pos: usize) -> MatchResult {
if pos == 0 {
if el_buf == b'\r' || el_buf == b'\n' {
self.prev_char = el_buf;
MatchResult::NeedNext
} else {
MatchResult::Mismatch
}
} else if pos == 1 {
if el_buf == b'\n' && self.prev_char == b'\r' {
MatchResult::Match(0, 0) } else {
MatchResult::Match(0, 1) }
} else {
panic!("We can't reach this code since we just manage 2 positions")
}
}
fn sequel_eos(&mut self, pos: usize) -> MatchResult {
if pos == 0 {
MatchResult::Match(0, 0) } else {
panic!("We can't reach this code since we just manage 2 positions")
}
}
}