use crowbook_text_processing::clean;
use crowbook_text_processing::FrenchFormatter;
use std::borrow::Cow;
pub struct CleanerParams {
pub smart_quotes: bool,
pub ligature_guillemets: bool,
pub ligature_dashes: bool,
}
pub trait Cleaner: Sync {
fn clean<'a>(&self, str: Cow<'a, str>) -> Cow<'a, str> {
str
}
}
pub struct Off;
impl Cleaner for Off {}
pub struct Default {
params: CleanerParams,
}
impl Default {
pub fn new(params: CleanerParams) -> Default {
Default { params }
}
}
impl Cleaner for Default {
fn clean<'a>(&self, input: Cow<'a, str>) -> Cow<'a, str> {
let mut s = clean::whitespaces(input);
if self.params.smart_quotes {
s = clean::quotes(s);
}
if self.params.ligature_dashes {
s = clean::dashes(s);
}
if self.params.ligature_guillemets {
s = clean::guillemets(s);
}
s
}
}
pub struct French {
formatter: FrenchFormatter,
params: CleanerParams,
}
impl French {
pub fn new(params: CleanerParams) -> French {
let mut this = French {
formatter: FrenchFormatter::new(),
params,
};
this.formatter.typographic_quotes(this.params.smart_quotes);
this.formatter.ligature_dashes(this.params.ligature_dashes);
this.formatter
.ligature_guillemets(this.params.ligature_guillemets);
this
}
}
impl Cleaner for French {
fn clean<'a>(&self, s: Cow<'a, str>) -> Cow<'a, str> {
self.formatter.format(s)
}
}