Trait regex::re_trait::RegularExpression [−][src]
pub trait RegularExpression: Sized { type Text: ?Sized; fn slots_len(&self) -> usize; fn next_after_empty(&self, text: &Self::Text, i: usize) -> usize; fn shortest_match_at(
&self,
text: &Self::Text,
start: usize
) -> Option<usize>; fn is_match_at(&self, text: &Self::Text, start: usize) -> bool; fn find_at(&self, text: &Self::Text, start: usize) -> Option<(usize, usize)>; fn read_captures_at(
&self,
locs: &mut Locations,
text: &Self::Text,
start: usize
) -> Option<(usize, usize)>; fn locations(&self) -> Locations { ... } fn find_iter(self, text: &Self::Text) -> Matches<Self> { ... } fn captures_iter(self, text: &Self::Text) -> CaptureMatches<Self> { ... } }
RegularExpression
describes types that can implement regex searching.
This trait is my attempt at reducing code duplication and to standardize
the internal API. Specific duplication that is avoided are the find
and capture
iterators, which are slightly tricky.
It's not clear whether this trait is worth it, and it also isn't
clear whether it's useful as a public trait or not. Methods like
next_after_empty
reak of bad design, but the rest of the methods seem
somewhat reasonable. One particular thing this trait would expose would be
the ability to start the search of a regex anywhere in a haystack, which
isn't possible in the current public API.
Associated Types
Required Methods
fn slots_len(&self) -> usize
The number of capture slots in the compiled regular expression. This is always two times the number of capture groups (two slots per group).
fn next_after_empty(&self, text: &Self::Text, i: usize) -> usize
Returns the position of the next character after i
.
For example, a haystack with type &[u8]
probably returns i+1
,
whereas a haystack with type &str
probably returns i
plus the
length of the next UTF-8 sequence.
fn shortest_match_at(&self, text: &Self::Text, start: usize) -> Option<usize>
Returns the location of the shortest match.
fn is_match_at(&self, text: &Self::Text, start: usize) -> bool
Returns whether the regex matches the text given.
fn find_at(&self, text: &Self::Text, start: usize) -> Option<(usize, usize)>
Returns the leftmost-first match location if one exists.
fn read_captures_at(
&self,
locs: &mut Locations,
text: &Self::Text,
start: usize
) -> Option<(usize, usize)>
&self,
locs: &mut Locations,
text: &Self::Text,
start: usize
) -> Option<(usize, usize)>
Returns the leftmost-first match location if one exists, and also fills in any matching capture slot locations.
Provided Methods
fn locations(&self) -> Locations
Allocates fresh space for all capturing groups in this regex.
fn find_iter(self, text: &Self::Text) -> Matches<Self>
Returns an iterator over all non-overlapping successive leftmost-first matches.
fn captures_iter(self, text: &Self::Text) -> CaptureMatches<Self>
Returns an iterator over all non-overlapping successive leftmost-first matches with captures.
Implementors
impl<'c> RegularExpression for ExecNoSyncStr<'c> type Text = str;
impl<'c> RegularExpression for ExecNoSync<'c> type Text = [u8];