summaryrefslogtreecommitdiffstats
path: root/vendor/anstyle-parse/src/state/mod.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /vendor/anstyle-parse/src/state/mod.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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 000000000..919420595
--- /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]
+}