Struct Pattern

Source
pub struct Pattern { /* private fields */ }
Expand description

A compiled pattern string that can be used to search text.

Implementations§

Source§

impl Pattern

Source

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.

Source

pub fn len(&self) -> usize

Returns the length of the pattern in characters.

Source

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));
Source

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 }));
Source

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 }));
Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.