pub struct Filter { /* private fields */ }
Expand description
Filter
demonstrates the use of FilteredRE2
by using
Set
as the backing search engine for the atoms produced by compile()
.
use re2::{filtered::*, options::*, set::*};
let mut builder = FilteredRE2Builder::with_min_atom_length(1);
let x = builder.add("asdf", Options::default())?;
let y = builder.add("asay", Options::default())?;
let z = builder.add("as+", Options::default())?;
let filter = Filter::compile(builder)?;
let mut atoms = MatchedSetInfo::empty();
let mut matches = MatchedSetInfo::empty();
assert!(filter.all_matches("asdf asay asinine", &mut atoms, &mut matches));
assert_eq!(matches.as_expression_slice(), &[x, y, z]);
let matched_atoms: Vec<&str> = filter.get_atoms(&atoms)
.map(|s| unsafe { s.as_str() })
.collect();
assert_eq!(&matched_atoms, &["a", "s", "asdf", "asay"]);
let matched_regexps: Vec<&str> = filter.get_matches(&matches)
.map(|r| r.as_re2().pattern())
.collect();
assert_eq!(&matched_regexps, &["asdf", "asay", "as+"]);
assert!(filter.potential_matches("asdf asay asinine", &mut atoms, &mut matches));
assert_eq!(matches.as_expression_slice(), &[x, y, z]);
Implementations§
Source§impl Filter
impl Filter
Sourcepub fn compile(builder: FilteredRE2Builder) -> Result<Self, SetError>
pub fn compile(builder: FilteredRE2Builder) -> Result<Self, SetError>
Sourcepub fn all_matches(
&self,
text: &str,
atoms: &mut MatchedSetInfo,
matches: &mut MatchedSetInfo,
) -> bool
pub fn all_matches( &self, text: &str, atoms: &mut MatchedSetInfo, matches: &mut MatchedSetInfo, ) -> bool
Get all patterns matching text
contributing to atoms
in matches
.
Sourcepub fn potential_matches(
&self,
text: &str,
atoms: &mut MatchedSetInfo,
matches: &mut MatchedSetInfo,
) -> bool
pub fn potential_matches( &self, text: &str, atoms: &mut MatchedSetInfo, matches: &mut MatchedSetInfo, ) -> bool
Get all patterns contributing to the atoms
which were found in text
into matches
.
Sourcepub fn get_atoms<'a>(
&'a self,
atoms: &'a MatchedSetInfo,
) -> impl ExactSizeIterator<Item = StringView<'a>>
pub fn get_atoms<'a>( &'a self, atoms: &'a MatchedSetInfo, ) -> impl ExactSizeIterator<Item = StringView<'a>>
Look up the atom strings referenced in atoms
.
Sourcepub fn get_matches<'a>(
&'a self,
matches: &'a MatchedSetInfo,
) -> impl ExactSizeIterator<Item = InnerRE2<'a>>
pub fn get_matches<'a>( &'a self, matches: &'a MatchedSetInfo, ) -> impl ExactSizeIterator<Item = InnerRE2<'a>>
Look up the pattern objects referenced in matches
.
Auto Trait Implementations§
impl Freeze for Filter
impl RefUnwindSafe for Filter
impl Send for Filter
impl Sync for Filter
impl Unpin for Filter
impl UnwindSafe for Filter
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