pub struct Pattern { /* private fields */ }
Expand description
A compiled pattern string that can be used to search text.
Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn new(pattern: &str) -> Result<Pattern, &'static str>
pub fn new(pattern: &str) -> Result<Pattern, &'static str>
Compiles and returns a new pattern from the passed string. Will fail if the passed pattern is empty or longer than the system word size.
Sourcepub fn find<'a>(&'a self, text: &'a str) -> impl Iterator<Item = usize> + 'a
pub fn find<'a>(&'a self, text: &'a str) -> impl Iterator<Item = usize> + 'a
Returns an iterator of character indexes where the pattern can be found within the passed text.
Unlike str::matches
, it will find and return overlapping matches.
use bitap::{Pattern};
let pattern = Pattern::new("world")?;
assert_eq!(pattern.find("hello world").next(), Some(6));
Sourcepub fn lev<'a>(
&'a self,
text: &'a str,
max_distance: usize,
) -> impl Iterator<Item = Match> + 'a
pub fn lev<'a>( &'a self, text: &'a str, max_distance: usize, ) -> impl Iterator<Item = Match> + 'a
Returns an iterator of matches where the pattern matched the passed
text within a levenshtein distance of max_distance
.
use bitap::{Pattern,Match};
let pattern = Pattern::new("wxrld")?;
let m = pattern.lev("hello world", 1).next();
assert_eq!(m, Some(Match{ distance: 1, end: 10 }));
Sourcepub fn osa<'a>(
&'a self,
text: &'a str,
max_distance: usize,
) -> impl Iterator<Item = Match> + 'a
pub fn osa<'a>( &'a self, text: &'a str, max_distance: usize, ) -> impl Iterator<Item = Match> + 'a
Returns an iterator of matches where the pattern matched the passed
text within an optimal string alignment distance of max_distance
.
use bitap::{Pattern,Match};
let pattern = Pattern::new("wrold")?;
let m = pattern.osa("hello world", 1).next();
assert_eq!(m, Some(Match{ distance: 1, end: 10 }));
Sourcepub fn lev_static<'a>(
&'a self,
text: &'a str,
max_distance: StaticMaxDistance,
) -> impl Iterator<Item = Match> + 'a
pub fn lev_static<'a>( &'a self, text: &'a str, max_distance: StaticMaxDistance, ) -> impl Iterator<Item = Match> + 'a
The same as lev, but optimized for a max_distance
of 1-2.
Sourcepub fn osa_static<'a>(
&'a self,
text: &'a str,
max_distance: StaticMaxDistance,
) -> impl Iterator<Item = Match> + 'a
pub fn osa_static<'a>( &'a self, text: &'a str, max_distance: StaticMaxDistance, ) -> impl Iterator<Item = Match> + 'a
The same as osa, but optimized for a max_distance
of 1-2.
Auto Trait Implementations§
impl Freeze for Pattern
impl RefUnwindSafe for Pattern
impl Send for Pattern
impl Sync for Pattern
impl Unpin for Pattern
impl UnwindSafe for Pattern
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