[−][src]Struct bitap::Pattern
A compiled pattern string that can be used to search text.
Methods
impl Pattern
[src]
pub fn new(pattern: &str) -> Result<Pattern, &'static str>
[src]
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.
pub fn len(&self) -> usize
[src]
Returns the length of the pattern in characters.
pub fn find<'a>(&'a self, text: &'a str) -> impl Iterator<Item = usize> + 'a
[src]
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));
pub fn lev<'a>(
&'a self,
text: &'a str,
max_distance: usize
) -> impl Iterator<Item = Match> + 'a
[src]
&'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 }));
pub fn osa<'a>(
&'a self,
text: &'a str,
max_distance: usize
) -> impl Iterator<Item = Match> + 'a
[src]
&'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 }));
pub fn lev_static<'a>(
&'a self,
text: &'a str,
max_distance: StaticMaxDistance
) -> impl Iterator<Item = Match> + 'a
[src]
&'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.
pub fn osa_static<'a>(
&'a self,
text: &'a str,
max_distance: StaticMaxDistance
) -> impl Iterator<Item = Match> + 'a
[src]
&'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 Sync for Pattern
impl Unpin for Pattern
impl Send for Pattern
impl UnwindSafe for Pattern
impl RefUnwindSafe for Pattern
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,