use std::path::Path; use std::str::FromStr; use once_cell::sync::Lazy; use regex::Regex; use crate::common::{Codepoint, CodepointIter, UcdFile, UcdFileByCodepoint}; use crate::error::Error; /// A single row in the `NameAliases.txt` file. /// /// Note that there are multiple rows for some codepoint. Each row provides a /// new alias. #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct NameAlias { /// The codepoint corresponding to this row. pub codepoint: Codepoint, /// The alias. pub alias: String, /// The label of this alias. pub label: NameAliasLabel, } impl UcdFile for NameAlias { fn relative_file_path() -> &'static Path { Path::new("NameAliases.txt") } } impl UcdFileByCodepoint for NameAlias { fn codepoints(&self) -> CodepointIter { self.codepoint.into_iter() } } impl FromStr for NameAlias { type Err = Error; fn from_str(line: &str) -> Result { static PARTS: Lazy = Lazy::new(|| { Regex::new( r"(?x) ^ (?P[A-Z0-9]+); \s* (?P[^;]+); \s* (?P