1#[cfg(test)]
2mod codegen;
3mod definitions;
4mod table;
5
6#[cfg(test)]
7pub(crate) use definitions::pack;
8pub(crate) use definitions::unpack;
9pub use definitions::Action;
10pub use definitions::State;
11
12/// Transition to next [`State`]
13///
14/// Note: This does not directly support UTF-8.
15/// - If the data is validated as UTF-8 (e.g. `str`) or single-byte C1 control codes are
16/// unsupported, then treat [`Action::BeginUtf8`] and [`Action::Execute`] for UTF-8 continuations
17/// as [`Action::Print`].
18/// - If the data is not validated, then a UTF-8 state machine will need to be implemented on top,
19/// starting with [`Action::BeginUtf8`].
20///
21/// Note: When [`State::Anywhere`] is returned, revert back to the prior state.
22#[inline]
23pub const fn state_change(state: State, byte: u8) -> (State, Action) {
24 // Handle state changes in the anywhere state before evaluating changes
25 // for current state.
26 let mut change: u8 = state_change_(State::Anywhere, byte);
27 if change == 0 {
28 change = state_change_(state, byte);
29 }
30
31 // Unpack into a state and action
32 unpack(delta:change)
33}
34
35#[inline]
36const fn state_change_(state: State, byte: u8) -> u8 {
37 let state_idx: usize = state as usize;
38 let byte_idx: usize = byte as usize;
39
40 table::STATE_CHANGES[state_idx][byte_idx]
41}
42