Struct grep_regex::RegexMatcher
source · pub struct RegexMatcher { /* private fields */ }
Expand description
An implementation of the Matcher
trait using Rust’s standard regex
library.
Implementations§
source§impl RegexMatcher
impl RegexMatcher
sourcepub fn new(pattern: &str) -> Result<RegexMatcher, Error>
pub fn new(pattern: &str) -> Result<RegexMatcher, Error>
Create a new matcher from the given pattern using the default configuration.
sourcepub fn new_line_matcher(pattern: &str) -> Result<RegexMatcher, Error>
pub fn new_line_matcher(pattern: &str) -> Result<RegexMatcher, Error>
Create a new matcher from the given pattern using the default
configuration, but matches lines terminated by \n
.
This is meant to be a convenience constructor for
using a RegexMatcherBuilder
and setting its
line_terminator
to
\n
. The purpose of using this constructor is to permit special
optimizations that help speed up line oriented search. These types of
optimizations are only appropriate when matches span no more than one
line. For this reason, this constructor will return an error if the
given pattern contains a literal \n
. Other uses of \n
(such as in
\s
) are removed transparently.
Trait Implementations§
source§impl Clone for RegexMatcher
impl Clone for RegexMatcher
source§fn clone(&self) -> RegexMatcher
fn clone(&self) -> RegexMatcher
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for RegexMatcher
impl Debug for RegexMatcher
source§impl Matcher for RegexMatcher
impl Matcher for RegexMatcher
§type Captures = RegexCaptures
type Captures = RegexCaptures
The concrete type of capturing groups used for this matcher. Read more
source§fn find_at(&self, haystack: &[u8], at: usize) -> Result<Option<Match>, NoError>
fn find_at(&self, haystack: &[u8], at: usize) -> Result<Option<Match>, NoError>
Returns the start and end byte range of the first match in
haystack
after at
, where the byte offsets are relative to that start of
haystack
(and not at
). If no match exists, then None
is returned. Read moresource§fn new_captures(&self) -> Result<RegexCaptures, NoError>
fn new_captures(&self) -> Result<RegexCaptures, NoError>
Creates an empty group of captures suitable for use with the capturing
APIs of this trait. Read more
source§fn capture_count(&self) -> usize
fn capture_count(&self) -> usize
Returns the total number of capturing groups in this matcher. Read more
source§fn capture_index(&self, name: &str) -> Option<usize>
fn capture_index(&self, name: &str) -> Option<usize>
Maps the given capture group name to its corresponding capture group
index, if one exists. If one does not exist, then
None
is returned. Read moresource§fn try_find_iter<F, E>(
&self,
haystack: &[u8],
matched: F
) -> Result<Result<(), E>, NoError>where
F: FnMut(Match) -> Result<bool, E>,
fn try_find_iter<F, E>( &self, haystack: &[u8], matched: F ) -> Result<Result<(), E>, NoError>where F: FnMut(Match) -> Result<bool, E>,
Executes the given function over successive non-overlapping matches
in
haystack
. If no match exists, then the given function is never
called. If the function returns false
, then iteration stops.
Similarly, if the function returns an error then iteration stops and
the error is yielded. If an error occurs while executing the search,
then it is converted to
E
.source§fn captures_at(
&self,
haystack: &[u8],
at: usize,
caps: &mut RegexCaptures
) -> Result<bool, NoError>
fn captures_at( &self, haystack: &[u8], at: usize, caps: &mut RegexCaptures ) -> Result<bool, NoError>
Populates the first set of capture group matches from
haystack
into matches
after at
, where the byte offsets in each capturing
group are relative to the start of haystack
(and not at
). If no
match exists, then false
is returned and the contents of the given
capturing groups are unspecified. Read moresource§fn shortest_match_at(
&self,
haystack: &[u8],
at: usize
) -> Result<Option<usize>, NoError>
fn shortest_match_at( &self, haystack: &[u8], at: usize ) -> Result<Option<usize>, NoError>
Returns an end location of the first match in
haystack
starting at
the given position. If no match exists, then None
is returned. Read moresource§fn non_matching_bytes(&self) -> Option<&ByteSet>
fn non_matching_bytes(&self) -> Option<&ByteSet>
If available, return a set of bytes that will never appear in a match
produced by an implementation. Read more
source§fn line_terminator(&self) -> Option<LineTerminator>
fn line_terminator(&self) -> Option<LineTerminator>
If this matcher was compiled as a line oriented matcher, then this
method returns the line terminator if and only if the line terminator
never appears in any match produced by this matcher. If this wasn’t
compiled as a line oriented matcher, or if the aforementioned guarantee
cannot be made, then this must return
None
, which is the default.
It is never wrong to return None
, but returning a line terminator
when it can appear in a match results in unspecified behavior. Read moresource§fn find_candidate_line(
&self,
haystack: &[u8]
) -> Result<Option<LineMatchKind>, NoError>
fn find_candidate_line( &self, haystack: &[u8] ) -> Result<Option<LineMatchKind>, NoError>
Return one of the following: a confirmed line match, a candidate line
match (which may be a false positive) or no match at all (which must
not be a false negative). When reporting a confirmed or candidate
match, the position returned can be any position in the line. Read more
source§fn find(&self, haystack: &[u8]) -> Result<Option<Match>, Self::Error>
fn find(&self, haystack: &[u8]) -> Result<Option<Match>, Self::Error>
Returns the start and end byte range of the first match in
haystack
.
If no match exists, then None
is returned. Read moresource§fn find_iter<F>(&self, haystack: &[u8], matched: F) -> Result<(), Self::Error>where
F: FnMut(Match) -> bool,
fn find_iter<F>(&self, haystack: &[u8], matched: F) -> Result<(), Self::Error>where F: FnMut(Match) -> bool,
Executes the given function over successive non-overlapping matches
in
haystack
. If no match exists, then the given function is never
called. If the function returns false
, then iteration stops.source§fn find_iter_at<F>(
&self,
haystack: &[u8],
at: usize,
matched: F
) -> Result<(), Self::Error>where
F: FnMut(Match) -> bool,
fn find_iter_at<F>( &self, haystack: &[u8], at: usize, matched: F ) -> Result<(), Self::Error>where F: FnMut(Match) -> bool,
Executes the given function over successive non-overlapping matches
in
haystack
. If no match exists, then the given function is never
called. If the function returns false
, then iteration stops. Read moresource§fn try_find_iter_at<F, E>(
&self,
haystack: &[u8],
at: usize,
matched: F
) -> Result<Result<(), E>, Self::Error>where
F: FnMut(Match) -> Result<bool, E>,
fn try_find_iter_at<F, E>( &self, haystack: &[u8], at: usize, matched: F ) -> Result<Result<(), E>, Self::Error>where F: FnMut(Match) -> Result<bool, E>,
Executes the given function over successive non-overlapping matches
in
haystack
. If no match exists, then the given function is never
called. If the function returns false
, then iteration stops.
Similarly, if the function returns an error then iteration stops and
the error is yielded. If an error occurs while executing the search,
then it is converted to
E
. Read moresource§fn captures(
&self,
haystack: &[u8],
caps: &mut Self::Captures
) -> Result<bool, Self::Error>
fn captures( &self, haystack: &[u8], caps: &mut Self::Captures ) -> Result<bool, Self::Error>
Populates the first set of capture group matches from
haystack
into
caps
. If no match exists, then false
is returned. Read moresource§fn captures_iter<F>(
&self,
haystack: &[u8],
caps: &mut Self::Captures,
matched: F
) -> Result<(), Self::Error>where
F: FnMut(&Self::Captures) -> bool,
fn captures_iter<F>( &self, haystack: &[u8], caps: &mut Self::Captures, matched: F ) -> Result<(), Self::Error>where F: FnMut(&Self::Captures) -> bool,
Executes the given function over successive non-overlapping matches
in
haystack
with capture groups extracted from each match. If no
match exists, then the given function is never called. If the function
returns false
, then iteration stops.source§fn captures_iter_at<F>(
&self,
haystack: &[u8],
at: usize,
caps: &mut Self::Captures,
matched: F
) -> Result<(), Self::Error>where
F: FnMut(&Self::Captures) -> bool,
fn captures_iter_at<F>( &self, haystack: &[u8], at: usize, caps: &mut Self::Captures, matched: F ) -> Result<(), Self::Error>where F: FnMut(&Self::Captures) -> bool,
Executes the given function over successive non-overlapping matches
in
haystack
with capture groups extracted from each match. If no
match exists, then the given function is never called. If the function
returns false
, then iteration stops. Read moresource§fn try_captures_iter<F, E>(
&self,
haystack: &[u8],
caps: &mut Self::Captures,
matched: F
) -> Result<Result<(), E>, Self::Error>where
F: FnMut(&Self::Captures) -> Result<bool, E>,
fn try_captures_iter<F, E>( &self, haystack: &[u8], caps: &mut Self::Captures, matched: F ) -> Result<Result<(), E>, Self::Error>where F: FnMut(&Self::Captures) -> Result<bool, E>,
Executes the given function over successive non-overlapping matches
in
haystack
with capture groups extracted from each match. If no
match exists, then the given function is never called. If the function
returns false
, then iteration stops. Similarly, if the function
returns an error then iteration stops and the error is yielded. If
an error occurs while executing the search, then it is converted to
E
.source§fn try_captures_iter_at<F, E>(
&self,
haystack: &[u8],
at: usize,
caps: &mut Self::Captures,
matched: F
) -> Result<Result<(), E>, Self::Error>where
F: FnMut(&Self::Captures) -> Result<bool, E>,
fn try_captures_iter_at<F, E>( &self, haystack: &[u8], at: usize, caps: &mut Self::Captures, matched: F ) -> Result<Result<(), E>, Self::Error>where F: FnMut(&Self::Captures) -> Result<bool, E>,
Executes the given function over successive non-overlapping matches
in
haystack
with capture groups extracted from each match. If no
match exists, then the given function is never called. If the function
returns false
, then iteration stops. Similarly, if the function
returns an error then iteration stops and the error is yielded. If
an error occurs while executing the search, then it is converted to
E
. Read moresource§fn replace<F>(
&self,
haystack: &[u8],
dst: &mut Vec<u8, Global>,
append: F
) -> Result<(), Self::Error>where
F: FnMut(Match, &mut Vec<u8, Global>) -> bool,
fn replace<F>( &self, haystack: &[u8], dst: &mut Vec<u8, Global>, append: F ) -> Result<(), Self::Error>where F: FnMut(Match, &mut Vec<u8, Global>) -> bool,
Replaces every match in the given haystack with the result of calling
append
. append
is given the start and end of a match, along with
a handle to the dst
buffer provided. Read moresource§fn replace_with_captures<F>(
&self,
haystack: &[u8],
caps: &mut Self::Captures,
dst: &mut Vec<u8, Global>,
append: F
) -> Result<(), Self::Error>where
F: FnMut(&Self::Captures, &mut Vec<u8, Global>) -> bool,
fn replace_with_captures<F>( &self, haystack: &[u8], caps: &mut Self::Captures, dst: &mut Vec<u8, Global>, append: F ) -> Result<(), Self::Error>where F: FnMut(&Self::Captures, &mut Vec<u8, Global>) -> bool,
Replaces every match in the given haystack with the result of calling
append
with the matching capture groups. Read moresource§fn replace_with_captures_at<F>(
&self,
haystack: &[u8],
at: usize,
caps: &mut Self::Captures,
dst: &mut Vec<u8, Global>,
append: F
) -> Result<(), Self::Error>where
F: FnMut(&Self::Captures, &mut Vec<u8, Global>) -> bool,
fn replace_with_captures_at<F>( &self, haystack: &[u8], at: usize, caps: &mut Self::Captures, dst: &mut Vec<u8, Global>, append: F ) -> Result<(), Self::Error>where F: FnMut(&Self::Captures, &mut Vec<u8, Global>) -> bool,
Replaces every match in the given haystack with the result of calling
append
with the matching capture groups. Read moresource§fn is_match(&self, haystack: &[u8]) -> Result<bool, Self::Error>
fn is_match(&self, haystack: &[u8]) -> Result<bool, Self::Error>
Returns true if and only if the matcher matches the given haystack. Read more
Auto Trait Implementations§
impl RefUnwindSafe for RegexMatcher
impl Send for RegexMatcher
impl Sync for RegexMatcher
impl Unpin for RegexMatcher
impl UnwindSafe for RegexMatcher
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more