sashite-feen 0.1.0

Field Expression Encoding Notation (FEEN): a compact, ASCII-only, no_std, zero-allocation validator and encoder for board-game positions in abstract strategy games, built on EPIN and SIN.
Documentation
//! Shared EPIN-token scanning used by both the placement and hands fields.

/// Returns the length and parsed value of the maximal valid EPIN token at the
/// start of `bytes`, or `None` if none begins there.
///
/// An EPIN token is at most four bytes (`[-+]?[A-Za-z]\^?'?`), so this probes
/// candidate lengths from four down to one and returns the first that parses —
/// the maximal munch. Any candidate that would cross a field delimiter is
/// rejected by EPIN itself, so no delimiter handling is needed here.
pub(crate) fn epin_token(bytes: &[u8]) -> Option<(usize, sashite_epin::Identifier)> {
    let mut len = if bytes.len() < 4 { bytes.len() } else { 4 };
    while len >= 1 {
        if let Ok(id) = sashite_epin::Identifier::try_from(&bytes[..len]) {
            return Some((len, id));
        }
        len -= 1;
    }
    None
}