[−][src]Trait nom::lib::std::str::pattern::Searcher
🔬 This is a nightly-only experimental API. (pattern
)
API not fully fleshed out and ready to be stabilized
A searcher for a string pattern.
This trait provides methods for searching for non-overlapping matches of a pattern starting from the front (left) of a string.
It will be implemented by associated Searcher
types of the [Pattern
] trait.
The trait is marked unsafe because the indices returned by the
[next()
][Searcher::next] methods are required to lie on valid utf8
boundaries in the haystack. This enables consumers of this trait to
slice the haystack without additional runtime checks.
Required methods
fn haystack(&self) -> &'a str
🔬 This is a nightly-only experimental API. (pattern
)
API not fully fleshed out and ready to be stabilized
Getter for the underlying string to be searched in
Will always return the same [&str
][str].
fn next(&mut self) -> SearchStep
🔬 This is a nightly-only experimental API. (pattern
)
API not fully fleshed out and ready to be stabilized
Performs the next search step starting from the front.
- Returns [
Match(a, b)
][SearchStep::Match] ifhaystack[a..b]
matches the pattern. - Returns [
Reject(a, b)
][SearchStep::Reject] ifhaystack[a..b]
can not match the pattern, even partially. - Returns [
Done
][SearchStep::Done] if every byte of the haystack has been visited.
The stream of [Match
][SearchStep::Match] and
[Reject
][SearchStep::Reject] values up to a [Done
][SearchStep::Done]
will contain index ranges that are adjacent, non-overlapping,
covering the whole haystack, and laying on utf8 boundaries.
A [Match
][SearchStep::Match] result needs to contain the whole matched
pattern, however [Reject
][SearchStep::Reject] results may be split up
into arbitrary many adjacent fragments. Both ranges may have zero length.
As an example, the pattern "aaa"
and the haystack "cbaaaaab"
might produce the stream
[Reject(0, 1), Reject(1, 2), Match(2, 5), Reject(5, 8)]
Provided methods
fn next_match(&mut self) -> Option<(usize, usize)>
🔬 This is a nightly-only experimental API. (pattern
)
API not fully fleshed out and ready to be stabilized
Finds the next [Match
][SearchStep::Match] result. See [next()
][Searcher::next].
Unlike [next()
][Searcher::next], there is no guarantee that the returned ranges
of this and [next_reject
][Searcher::next_reject] will overlap. This will return
(start_match, end_match)
, where start_match is the index of where
the match begins, and end_match is the index after the end of the match.
fn next_reject(&mut self) -> Option<(usize, usize)>
🔬 This is a nightly-only experimental API. (pattern
)
API not fully fleshed out and ready to be stabilized
Finds the next [Reject
][SearchStep::Reject] result. See [next()
][Searcher::next]
and [next_match()
][Searcher::next_match].
Unlike [next()
][Searcher::next], there is no guarantee that the returned ranges
of this and [next_match
][Searcher::next_match] will overlap.
Implementors
impl<'a> Searcher<'a> for CharSearcher<'a>
[src]
fn haystack(&self) -> &'a str
[src]
fn next(&mut self) -> SearchStep
[src]
fn next_match(&mut self) -> Option<(usize, usize)>
[src]
impl<'a, 'b> Searcher<'a> for CharSliceSearcher<'a, 'b>
[src]
fn haystack(&self) -> &'a str
[src]
fn next(&mut self) -> SearchStep
[src]
fn next_match(&mut self) -> Option<(usize, usize)>
[src]
fn next_reject(&mut self) -> Option<(usize, usize)>
[src]
impl<'a, 'b> Searcher<'a> for StrSearcher<'a, 'b>
[src]
fn haystack(&self) -> &'a str
[src]
fn next(&mut self) -> SearchStep
[src]
fn next_match(&mut self) -> Option<(usize, usize)>
[src]
impl<'a, F> Searcher<'a> for CharPredicateSearcher<'a, F> where
F: FnMut(char) -> bool,
[src]
F: FnMut(char) -> bool,