//! Code page tables. Everything except this module file is generated by
//! `tools/gen_tables.py` from the vendored Microsoft mapping tables in
//! `data/` — regenerate rather than editing by hand.

pub(crate) mod ansi;
pub(crate) mod dos;

#[cfg(feature = "dbcs")]
pub(crate) mod cp932;
#[cfg(feature = "dbcs")]
pub(crate) mod cp936;
#[cfg(feature = "dbcs")]
pub(crate) mod cp949;
#[cfg(feature = "dbcs")]
pub(crate) mod cp950;

/// One slot of a double-byte page's single-byte table.
#[cfg(feature = "dbcs")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum SingleEntry {
    /// The byte decodes to this character on its own.
    Map(char),
    /// The byte is a DBCS lead byte; a trail byte must follow.
    Lead,
    /// The code page leaves the byte undefined.
    Undefined,
}

/// A double-byte code page: the single-byte table plus sorted pair tables
/// for binary search in each direction.
#[cfg(feature = "dbcs")]
pub(crate) struct DbcsPage {
    /// How each lone byte value behaves.
    pub single: &'static [SingleEntry; 256],
    /// Every defined pair, sorted by 16-bit code (`lead << 8 | trail`).
    pub decode: &'static [(u16, char)],
    /// One pair per scalar, sorted by scalar; where several codes decode to
    /// one scalar, the winner matches Microsoft's bestfit WCTABLE.
    pub encode: &'static [(char, u16)],
}
