aboutsummaryrefslogtreecommitdiff
path: root/vendor/anstyle-parse/src/state/mod.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/anstyle-parse/src/state/mod.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/anstyle-parse/src/state/mod.rs')
-rw-r--r--vendor/anstyle-parse/src/state/mod.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/anstyle-parse/src/state/mod.rs b/vendor/anstyle-parse/src/state/mod.rs
new file mode 100644
index 0000000..9194205
--- /dev/null
+++ b/vendor/anstyle-parse/src/state/mod.rs
@@ -0,0 +1,41 @@
+#[cfg(test)]
+mod codegen;
+mod definitions;
+mod table;
+
+#[cfg(test)]
+pub(crate) use definitions::pack;
+pub(crate) use definitions::unpack;
+pub use definitions::Action;
+pub use definitions::State;
+
+/// Transition to next [`State`]
+///
+/// Note: This does not directly support UTF-8.
+/// - If the data is validated as UTF-8 (e.g. `str`) or single-byte C1 control codes are
+/// unsupported, then treat [`Action::BeginUtf8`] and [`Action::Execute`] for UTF-8 continuations
+/// as [`Action::Print`].
+/// - If the data is not validated, then a UTF-8 state machine will need to be implemented on top,
+/// starting with [`Action::BeginUtf8`].
+///
+/// Note: When [`State::Anywhere`] is returned, revert back to the prior state.
+#[inline]
+pub const fn state_change(state: State, byte: u8) -> (State, Action) {
+ // Handle state changes in the anywhere state before evaluating changes
+ // for current state.
+ let mut change = state_change_(State::Anywhere, byte);
+ if change == 0 {
+ change = state_change_(state, byte);
+ }
+
+ // Unpack into a state and action
+ unpack(change)
+}
+
+#[inline]
+const fn state_change_(state: State, byte: u8) -> u8 {
+ let state_idx = state as usize;
+ let byte_idx = byte as usize;
+
+ table::STATE_CHANGES[state_idx][byte_idx]
+}