use once_cell::sync::Lazy;
use std::collections::HashMap;
include!(concat!(env!("OUT_DIR"), "/text_confusables_gen.rs"));
static TEXT_CONFUSABLES_MAP: Lazy<HashMap<char, char>> = Lazy::new(|| {
let mut m = HashMap::with_capacity(TEXT_CONFUSABLE_COUNT);
for &(src, tgt) in TEXT_CONFUSABLE_TABLE {
if let (Some(s), Some(t)) = (char::from_u32(src), char::from_u32(tgt)) {
m.insert(s, t);
}
}
m
});
pub fn is_text_confusable(ch: char) -> Option<char> {
TEXT_CONFUSABLES_MAP.get(&ch).copied()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_math_bold_a() {
assert_eq!(is_text_confusable('\u{1D400}'), Some('A'));
}
#[test]
fn test_math_bold_lowercase() {
assert_eq!(is_text_confusable('\u{1D41A}'), Some('a'));
}
#[test]
fn test_math_bold_digit() {
assert_eq!(is_text_confusable('\u{1D7CE}'), Some('0'));
}
#[test]
fn test_ascii_not_confusable() {
assert_eq!(is_text_confusable('a'), None);
assert_eq!(is_text_confusable('A'), None);
assert_eq!(is_text_confusable('0'), None);
}
#[test]
fn test_math_monospace() {
assert_eq!(is_text_confusable('\u{1D670}'), Some('A'));
}
}