use std::fmt::Display; use convert_case::{Case, Casing}; use deunicode::deunicode; pub mod chapter; pub mod replacement; pub mod section; #[derive(PartialEq, Eq, PartialOrd, Ord)] pub struct MangledName(String); impl MangledName { pub fn new(name: &str) -> Self { let ascii_name = deunicode(&name); Self(ascii_name.to_case(Case::Snake)) } pub fn from_str_unsafe(name: &str) -> Self { Self(name.to_owned()) } pub fn check_mangled(name: &str) -> bool { let mangled = Self::new(name); let normal = Self::from_str_unsafe(name); mangled == normal } pub fn as_str(&self) -> &str { &self.0 } pub fn try_unmangle(self) -> String { self.0.to_case(Case::Title) } } impl Display for MangledName { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(&self.0) } }