use crate::SessionExtension;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FindCharRecord {
char: char,
forward: bool,
inclusive: bool,
}
impl FindCharRecord {
#[must_use]
pub const fn new(char: char, forward: bool, inclusive: bool) -> Self {
Self {
char,
forward,
inclusive,
}
}
#[must_use]
pub const fn char(&self) -> char {
self.char
}
#[must_use]
pub const fn forward(&self) -> bool {
self.forward
}
#[must_use]
pub const fn inclusive(&self) -> bool {
self.inclusive
}
#[must_use]
pub const fn reversed(&self) -> Self {
Self {
forward: !self.forward,
char: self.char,
inclusive: self.inclusive,
}
}
}
#[derive(Debug, Default)]
pub struct FindCharState {
last: Option<FindCharRecord>,
}
impl SessionExtension for FindCharState {
fn create() -> Self {
Self::default()
}
}
impl FindCharState {
pub const fn record(&mut self, char: char, forward: bool, inclusive: bool) {
self.last = Some(FindCharRecord::new(char, forward, inclusive));
}
#[must_use]
pub const fn last(&self) -> Option<&FindCharRecord> {
self.last.as_ref()
}
}
#[cfg(test)]
#[path = "tests/find_char.rs"]
mod tests;