include!(concat!(env!("OUT_DIR"), "/hanzi_pinyin_phf.rs"));
include!(concat!(env!("OUT_DIR"), "/hanzi_pinyin_toned_phf.rs"));
#[inline]
pub fn lookup_hanzi(ch: char) -> Option<&'static str> {
let off = usize::try_from((ch as u32).checked_sub(HANZI_PINYIN_BASE)?).ok()?;
let id = *HANZI_PINYIN_IDS.get(off)?;
(id != 0).then(|| HANZI_PINYIN_VALUES[id as usize])
}
#[inline]
pub fn lookup_hanzi_toned(ch: char) -> Option<&'static str> {
HANZI_PINYIN_TONED
.get(&ch)
.copied()
.or_else(|| lookup_hanzi(ch))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_lookup_basic() {
assert_eq!(lookup_hanzi('\u{4E00}'), Some("yi")); assert_eq!(lookup_hanzi('\u{4EAC}'), Some("jing")); }
#[test]
fn test_lookup_not_found() {
assert!(lookup_hanzi('a').is_none());
}
}