inputx-wubi 1.4.0

Self-developed Wubi 86 encoder, dictionary, and dataset — zero-dependency, self-built finite-state index (inputx-fsa), WASM-ready. Powers the Inputx IME.
Documentation
//! 一级简码 lookup, backed by a compile-time sorted `&[(u8, char)]` table
//! generated by `build.rs` from `data/jianma1.txt`. Binary search, zero
//! external deps (replaces the former phf::Map).
//!
//! 二级 / 三级简码 layers land in Phase 9.

include!(concat!(env!("OUT_DIR"), "/jianma1.phf.rs"));

/// Look up the 一级简码 character for a key letter (lowercase ASCII).
#[inline]
pub fn lookup_jianma1(letter: u8) -> Option<char> {
    let l = letter.to_ascii_lowercase();
    JIANMA1
        .binary_search_by_key(&l, |&(k, _)| k)
        .ok()
        .map(|i| JIANMA1[i].1)
}

/// Iterate all (letter, char) pairs (sorted by letter).
pub fn iter_jianma1() -> impl Iterator<Item = (u8, char)> + 'static {
    JIANMA1.iter().map(|&(k, v)| (k, v))
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn parses_25() {
        assert_eq!(JIANMA1.len(), 25);
        assert_eq!(lookup_jianma1(b'g'), Some(''));
        assert_eq!(lookup_jianma1(b'q'), Some(''));
        assert_eq!(lookup_jianma1(b'z'), None);
    }

    #[test]
    fn iter_jianma1_round_trips_through_lookup() {
        let pairs: Vec<_> = iter_jianma1().collect();
        assert_eq!(pairs.len(), 25);
        for (letter, ch) in pairs {
            assert_eq!(lookup_jianma1(letter), Some(ch));
        }
    }
}