pub struct Scanner { /* private fields */ }Implementations§
Source§impl Scanner
impl Scanner
pub fn new(finders: Vec<Box<dyn Finder>>) -> Self
pub fn try_new(finders: Vec<Box<dyn Finder>>) -> Result<Self, ScannerError>
pub fn finders(&self) -> &[Box<dyn Finder>]
Sourcepub fn set_strategy(&mut self, strategy: Strategy)
pub fn set_strategy(&mut self, strategy: Strategy)
Selects the line-walking strategy; results do not depend on it.
Sourcepub fn backend(&self) -> &'static str
pub fn backend(&self) -> &'static str
Name of the block classifier used by Strategy::Vector
("neon", "ssse3" or "scalar"), for diagnostics.
Sourcepub fn plan(&self) -> String
pub fn plan(&self) -> String
How Strategy::Vector searches candidates, for diagnostics: the
passes in order, such as anchors(-), start bytes(:@) or
blocks, joined with +.
pub fn scan_line(&self, line: &str) -> Vec<Match>
Sourcepub fn skip_to_candidate_line(&self, text: &[u8], from: usize) -> Option<usize>
pub fn skip_to_candidate_line(&self, text: &[u8], from: usize) -> Option<usize>
Start of the first line at or after from (itself a line start) in
text that may contain a match, or None when no later line can.
When the finders start at three bytes or fewer, those bytes are
searched with memchr across the whole buffer, so lines that cannot
match are never visited individually; otherwise every line is a
candidate and from is returned. Lines end at \n.
pub fn scan_line_into(&self, line: &str, matches: &mut Vec<Match>)
Sourcepub fn scan_line_stats(
&self,
line: &str,
matches: &mut Vec<Match>,
stats: &mut ScanStats,
)
pub fn scan_line_stats( &self, line: &str, matches: &mut Vec<Match>, stats: &mut ScanStats, )
Like scan_line_into, additionally counting
the work performed into stats.
Sourcepub fn scan_buffer(
&self,
text: &str,
emit: impl FnMut(usize, usize, &[Match]) -> bool,
) -> bool
pub fn scan_buffer( &self, text: &str, emit: impl FnMut(usize, usize, &[Match]) -> bool, ) -> bool
Scans every line of text in one pass over the buffer and calls
emit(line_start, line_end, matches) for each line with at least one
match, in order; line_end excludes the terminator and trailing
\rs, and the match ranges are relative to line_start, exactly as
scan_line would report them for that line.
Returns true when emit asked to stop.
With the vector strategy and no scan-mode finder the candidate search runs over the whole buffer and only lines holding a candidate are looked at, which is much cheaper than a call per line.
Sourcepub fn scan_buffer_matches(
&self,
text: &str,
emit: impl FnMut(usize, Range<usize>) -> bool,
) -> bool
pub fn scan_buffer_matches( &self, text: &str, emit: impl FnMut(usize, Range<usize>) -> bool, ) -> bool
Scans text like scan_buffer but hands every
match to emit(finder_index, range) with a range into text, in the
same order (by start, then finder), without resolving the lines
around them; a caller that prints values alone skips that work.
Returns true when emit asked to stop.
Sourcepub fn scan_line_first(&self, line: &str) -> Option<Match>
pub fn scan_line_first(&self, line: &str) -> Option<Match>
Returns the same match as scan_line(line).into_iter().next(): the
earliest-starting match, ties broken by the lowest finder index.