Struct Config
struct Config { ... }
The configuration used to determine a DFA's start state for a search.
A DFA has a single starting state in the typical textbook description. That is, it corresponds to the set of all starting states for the NFA that built it, along with their espsilon closures. In this crate, however, DFAs have many possible start states due to a few factors:
- DFAs support the ability to run either anchored or unanchored searches.
Each type of search needs its own start state. For example, an unanchored
search requires starting at a state corresponding to a regex with a
(?s-u:.)*?prefix, which will match through anything. - DFAs also optionally support starting an anchored search for any one specific pattern. Each such pattern requires its own start state.
- If a look-behind assertion like
^or\bis used in the regex, then the DFA will need to inspect a single byte immediately before the start of the search to choose the correct start state.
Indeed, this configuration precisely encapsulates all of the above factors.
The Config::anchored method sets which kind of anchored search to
perform while the Config::look_behind method provides a way to set
the byte that occurs immediately before the start of the search.
Generally speaking, this type is only useful when you want to run searches
without using an Input. In particular, an Input wants a haystack
slice, but callers may not have a contiguous sequence of bytes as a
haystack in all cases. This type provides a lower level of control such
that callers can provide their own anchored configuration and look-behind
byte explicitly.
Example
This shows basic usage that permits running a search with a DFA without
using the Input abstraction.
use ;
let dfa = DFAnew?;
let haystack = "quartz";
let config = new.anchored;
let mut state = dfa.start_state?;
for &b in haystack.as_bytes.iter
state = dfa.next_eoi_state;
assert!;
# Ok::
This example shows how to correctly run a search that doesn't begin at
the start of a haystack. Notice how we set the look-behind byte, and as
a result, the \b assertion does not match.
use ;
let dfa = DFAnew?;
let haystack = "quartz";
let config = new
.anchored
.look_behind;
let mut state = dfa.start_state?;
for &b in haystack.as_bytes.iter.skip
state = dfa.next_eoi_state;
// No match!
assert!;
# Ok::
If we had instead not set a look-behind byte, then the DFA would assume
that it was starting at the beginning of the haystack, and thus \b should
match. This in turn would result in erroneously reporting a match:
use ;
let dfa = DFAnew?;
let haystack = "quartz";
// Whoops, forgot the look-behind byte...
let config = new.anchored;
let mut state = dfa.start_state?;
for &b in haystack.as_bytes.iter.skip
state = dfa.next_eoi_state;
// And now we get a match unexpectedly.
assert!;
# Ok::
Implementations
impl Config
fn new() -> ConfigCreate a new default start configuration.
The default is an unanchored search that starts at the beginning of the haystack.
fn from_input_forward(input: &Input<'_>) -> ConfigA convenience routine for building a start configuration from an
Inputfor a forward search.This automatically sets the look-behind byte to the byte immediately preceding the start of the search. If the start of the search is at offset
0, then no look-behind byte is set.fn from_input_reverse(input: &Input<'_>) -> ConfigA convenience routine for building a start configuration from an
Inputfor a reverse search.This automatically sets the look-behind byte to the byte immediately following the end of the search. If the end of the search is at offset
haystack.len(), then no look-behind byte is set.fn look_behind(self: Self, byte: Option<u8>) -> ConfigSet the look-behind byte at the start of a search.
Unless the search is intended to logically start at the beginning of a haystack, this should always be set to the byte immediately preceding the start of the search. If no look-behind byte is set, then the start configuration will assume it is at the beginning of the haystack. For example, the anchor
^will match.The default is that no look-behind byte is set.
fn anchored(self: Self, mode: Anchored) -> ConfigSet the anchored mode of a search.
The default is an unanchored search.
fn get_look_behind(self: &Self) -> Option<u8>Return the look-behind byte in this configuration, if one exists.
fn get_anchored(self: &Self) -> AnchoredReturn the anchored mode in this configuration.
impl Clone for Config
fn clone(self: &Self) -> Config
impl Debug for Config
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
impl<T> Any for Config
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Config
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Config
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Config
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Config
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Config
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Config
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Config
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Config
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>