use crate::alias::{Alphabet, Cyrillic, Latin};
use crate::alphabet::exclusion;
use crate::alphabet::helper::class;
pub fn process(
alphabet: &Alphabet,
current: Cyrillic,
prev: Option<Cyrillic>,
next: Option<Cyrillic>,
) -> Latin {
match alphabet.get(¤t) {
Some(&converted) => {
if class::is_iotized(¤t) {
let use_exclusion = match prev {
Some(p) => !alphabet.contains_key(&p) || !class::is_consonant(&p),
None => true,
};
if use_exclusion {
return exclusion::jot::get()
.get(¤t)
.copied()
.unwrap_or(converted)
.to_string();
}
if let Some(p) = prev {
if class::is_sibilant(&p) {
return exclusion::basis::get()
.get(¤t)
.copied()
.unwrap_or(converted)
.to_string();
}
}
}
if class::is_soft(¤t) {
if let Some(p) = prev {
if class::is_sibilant(&p) {
return String::new();
}
}
if let Some(n) = next {
if class::is_iotized(&n) {
return String::new();
}
}
}
converted.to_string()
}
None => current.to_string(),
}
}