#![deny(missing_docs)]
#![no_std]
#[macro_use(format)]
extern crate alloc;
use alloc::borrow::Cow;
use alloc::string::String;
use core::convert::TryFrom;
mod aglfn;
mod aglfn_names;
pub use aglfn_names::GLYPH_NAME_PAIRS;
pub fn glyph_name(ch: u32) -> Option<Cow<'static, str>> {
char::try_from(ch).ok().map(|ch| {
aglfn::glyph_name(ch)
.map(Cow::from)
.unwrap_or_else(|| Cow::from(unicode_glyph_name(ch)))
})
}
fn unicode_glyph_name(ch: char) -> String {
let ch = ch as u32;
if ch <= 0xFFFF {
format!("uni{:04X}", ch)
} else {
format!("u{:04X}", ch)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_unicode_glyph_name() {
assert_eq!(&unicode_glyph_name('a'), "uni0061");
assert_eq!(&unicode_glyph_name('↣'), "uni21A3");
assert_eq!(&unicode_glyph_name('🕴'), "u1F574");
}
}