cranberry 0.1.0

A versatile Rust library for Russian Cyrillic transliteration
Documentation
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(&current) {
        Some(&converted) => {
            if class::is_iotized(&current) {
                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(&current)
                        .copied()
                        .unwrap_or(converted)
                        .to_string();
                }

                if let Some(p) = prev {
                    if class::is_sibilant(&p) {
                        return exclusion::basis::get()
                            .get(&current)
                            .copied()
                            .unwrap_or(converted)
                            .to_string();
                    }
                }
            }

            if class::is_soft(&current) {
                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(),
    }
}