#[derive(Debug, Default, Clone, Copy)]
pub(in crate::fix) struct Gap {
open: bool,
}
impl Gap {
pub(in crate::fix) fn spaced(
written: &str,
to: String,
word: bool,
) -> String {
let after = written.chars().next_back().is_some_and(joins);
if word && after && to.chars().next().is_some_and(joins) {
return format!(" {to}");
}
to
}
pub(in crate::fix) fn written(&mut self, to: &str) {
self.open = to.chars().next_back().is_some_and(joins);
}
pub(in crate::fix) fn close(&mut self, text: &str) -> bool {
let space = self.open && text.chars().next().is_some_and(joins);
self.open = self.open && text.is_empty();
space
}
}
fn joins(ch: char) -> bool {
ch.is_alphanumeric() || ch == '_'
}