diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:25 +0000 |
commit | 5363f350887b1e5b5dd21a86f88c8af9d7fea6da (patch) | |
tree | 35ca005eb6e0e9a1ba3bb5dbc033209ad445dc17 /vendor/regex-automata/src/transducer.rs | |
parent | Adding debian version 1.66.0+dfsg1-1. (diff) | |
download | rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.tar.xz rustc-5363f350887b1e5b5dd21a86f88c8af9d7fea6da.zip |
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/regex-automata/src/transducer.rs')
-rw-r--r-- | vendor/regex-automata/src/transducer.rs | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/vendor/regex-automata/src/transducer.rs b/vendor/regex-automata/src/transducer.rs deleted file mode 100644 index 679c75726..000000000 --- a/vendor/regex-automata/src/transducer.rs +++ /dev/null @@ -1,107 +0,0 @@ -use fst::Automaton; - -use crate::{StateID, DFA}; - -macro_rules! imp { - ($ty:ty, $id:ty) => { - impl<T: AsRef<[$id]>, S: StateID> Automaton for $ty { - type State = S; - - #[inline] - fn start(&self) -> S { - self.start_state() - } - - #[inline] - fn is_match(&self, state: &S) -> bool { - self.is_match_state(*state) - } - - #[inline] - fn accept(&self, state: &S, byte: u8) -> S { - self.next_state(*state, byte) - } - - #[inline] - fn can_match(&self, state: &S) -> bool { - !self.is_dead_state(*state) - } - } - }; -} - -imp!(crate::dense::DenseDFA<T, S>, S); -imp!(crate::dense::Standard<T, S>, S); -imp!(crate::dense::ByteClass<T, S>, S); -imp!(crate::dense::Premultiplied<T, S>, S); -imp!(crate::dense::PremultipliedByteClass<T, S>, S); -imp!(crate::sparse::SparseDFA<T, S>, u8); -imp!(crate::sparse::Standard<T, S>, u8); -imp!(crate::sparse::ByteClass<T, S>, u8); - -#[cfg(test)] -mod tests { - use bstr::BString; - use fst::{Automaton, IntoStreamer, Set, Streamer}; - - use crate::dense::{self, DenseDFA}; - use crate::sparse::SparseDFA; - - fn search<A: Automaton, D: AsRef<[u8]>>( - set: &Set<D>, - aut: A, - ) -> Vec<BString> { - let mut stream = set.search(aut).into_stream(); - - let mut results = vec![]; - while let Some(key) = stream.next() { - results.push(BString::from(key)); - } - results - } - - #[test] - fn dense_anywhere() { - let set = - Set::from_iter(&["a", "bar", "baz", "wat", "xba", "xbax", "z"]) - .unwrap(); - let dfa = DenseDFA::new("ba.*").unwrap(); - let got = search(&set, &dfa); - assert_eq!(got, vec!["bar", "baz", "xba", "xbax"]); - } - - #[test] - fn dense_anchored() { - let set = - Set::from_iter(&["a", "bar", "baz", "wat", "xba", "xbax", "z"]) - .unwrap(); - let dfa = dense::Builder::new().anchored(true).build("ba.*").unwrap(); - let got = search(&set, &dfa); - assert_eq!(got, vec!["bar", "baz"]); - } - - #[test] - fn sparse_anywhere() { - let set = - Set::from_iter(&["a", "bar", "baz", "wat", "xba", "xbax", "z"]) - .unwrap(); - let dfa = SparseDFA::new("ba.*").unwrap(); - let got = search(&set, &dfa); - assert_eq!(got, vec!["bar", "baz", "xba", "xbax"]); - } - - #[test] - fn sparse_anchored() { - let set = - Set::from_iter(&["a", "bar", "baz", "wat", "xba", "xbax", "z"]) - .unwrap(); - let dfa = dense::Builder::new() - .anchored(true) - .build("ba.*") - .unwrap() - .to_sparse() - .unwrap(); - let got = search(&set, &dfa); - assert_eq!(got, vec!["bar", "baz"]); - } -} |