use super::insert_unique;
use std::collections::HashMap;
use std::sync::OnceLock;
pub type DiacriticRule = (&'static str, &'static str);
pub(crate) const HASANT: &str = "্";
pub(crate) const CHANDRABINDU: &str = "ঁ";
pub(crate) const VISARGA: &str = "ঃ";
pub(crate) const KHANDA_TA: &str = "ৎ";
pub(crate) const ANUSVARA: &str = "ং";
const DIACRITIC_RULES: &[DiacriticRule] = &[
(",,", HASANT),
("^", CHANDRABINDU), (":", VISARGA), ("t``", KHANDA_TA), ("T``", KHANDA_TA), ("ng", ANUSVARA), ("M", ANUSVARA), ];
fn build_diacritics() -> HashMap<&'static str, &'static str> {
let mut map = HashMap::with_capacity(DIACRITIC_RULES.len());
for &(roman, bengali) in DIACRITIC_RULES {
insert_unique(&mut map, "diacritic", roman, bengali);
}
map
}
pub const fn diacritic_rules() -> &'static [DiacriticRule] {
DIACRITIC_RULES
}
pub fn diacritic_value(roman: &str) -> Option<&'static str> {
match roman {
",," => Some(HASANT),
"^" => Some(CHANDRABINDU),
":" => Some(VISARGA),
"t``" | "T``" => Some(KHANDA_TA),
"ng" | "M" => Some(ANUSVARA),
_ => None,
}
}
pub fn diacritics_static() -> &'static HashMap<&'static str, &'static str> {
static INSTANCE: OnceLock<HashMap<&'static str, &'static str>> = OnceLock::new();
INSTANCE.get_or_init(build_diacritics)
}
pub fn diacritics() -> HashMap<&'static str, &'static str> {
diacritics_static().clone()
}