IbMatcher

Struct IbMatcher 

Source
pub struct IbMatcher<'a, HaystackStr = str>
where HaystackStr: EncodedStr + ?Sized,
{ /* private fields */ }
Expand description

§Example

// cargo add ib-matcher --features pinyin,romaji
use ib_matcher::{
    matcher::{IbMatcher, PinyinMatchConfig, RomajiMatchConfig},
    pinyin::PinyinNotation,
};

let matcher = IbMatcher::builder("la vie est drôle").build();
assert!(matcher.is_match("LA VIE EST DRÔLE"));

let matcher = IbMatcher::builder("βίος").build();
assert!(matcher.is_match("Βίοσ"));
assert!(matcher.is_match("ΒΊΟΣ"));

let matcher = IbMatcher::builder("pysousuoeve")
    .pinyin(PinyinMatchConfig::notations(
        PinyinNotation::Ascii | PinyinNotation::AsciiFirstLetter,
    ))
    .build();
assert!(matcher.is_match("拼音搜索Everything"));

let matcher = IbMatcher::builder("konosuba")
    .romaji(RomajiMatchConfig::default())
    .is_pattern_partial(true)
    .build();
assert!(matcher.is_match("この素晴らしい世界に祝福を"));

§Design

API follows regex::Regex.

§Performance

TODO: No-pinyin pattern optimization TODO: Anchors, *_at TODO: Unicode normalization TODO: No-hanzi haystack optimization (0.2/0.9%) TODO: If pattern doesn’t contain ., only match before . in the haystack

Implementations§

Source§

impl<'a, HaystackStr> IbMatcher<'a, HaystackStr>
where HaystackStr: EncodedStr + ?Sized,

Source

pub fn with_config<'p>( pattern: impl Into<Pattern<'p, HaystackStr>>, config: MatchConfig<'a>, ) -> Self
where HaystackStr: 'p,

Source

pub fn find<'h>( &'a self, input: impl Into<Input<'h, HaystackStr>>, ) -> Option<Match>
where HaystackStr: 'h,

This routine searches for the first match of this pattern in the haystack given, and if found, returns a Match. The Match provides access to both the byte offsets of the match and Match::is_pattern_partial().

Note that this should only be used if you want to find the entire match. If instead you just want to test the existence of a match, it’s potentially faster to use IbMatcher::is_match() instead of IbMatcher::find().is_some().

Source

pub fn is_match<'h>(&self, input: impl Into<Input<'h, HaystackStr>>) -> bool
where HaystackStr: 'h,

Returns true if and only if there is a match for the pattern anywhere in the haystack given.

It is recommended to use this method if all you need to do is test whether a match exists, since the underlying matching engine may be able to do less work.

Source

pub fn test<'h>( &self, input: impl Into<Input<'h, HaystackStr>>, ) -> Option<Match>
where HaystackStr: 'h,

This routine tests if this pattern matches the haystack at the start, and if found, returns a Match. The Match provides access to both the byte offsets of the match and Match::is_pattern_partial().

§Returns
  • Match.start() is guaranteed to be 0.
  • If there are multiple possible matches, the longer ones are preferred. But the result is not guaranteed to be the longest one.
Source

pub fn test_and_try_for_each<'h, T>( &self, input: impl Into<Input<'h, HaystackStr>>, f: &mut impl FnMut(Match) -> Option<T>, ) -> Option<T>
where HaystackStr: 'h,

This routine tests if this pattern matches the haystack at the start, and if found, calls f, and returns a [T] if it returns Some.

§Arguments
Source

pub fn is_haystack_too_short(&self, haystack: &HaystackStr) -> bool

Already tested in match methods.

Source

pub fn builder<'p>( pattern: impl Into<Pattern<'p, HaystackStr>>, ) -> IbMatcherBuilder<'a, 'p, HaystackStr>

Trait Implementations§

Source§

impl Debug for IbMatcher<'_, str>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, HaystackStr = str> !Freeze for IbMatcher<'a, HaystackStr>

§

impl<'a, HaystackStr> RefUnwindSafe for IbMatcher<'a, HaystackStr>
where HaystackStr: RefUnwindSafe + ?Sized,

§

impl<'a, HaystackStr> Send for IbMatcher<'a, HaystackStr>
where HaystackStr: Send + ?Sized,

§

impl<'a, HaystackStr> Sync for IbMatcher<'a, HaystackStr>
where HaystackStr: Sync + ?Sized,

§

impl<'a, HaystackStr> Unpin for IbMatcher<'a, HaystackStr>
where HaystackStr: Unpin + ?Sized,

§

impl<'a, HaystackStr> UnwindSafe for IbMatcher<'a, HaystackStr>
where HaystackStr: UnwindSafe + ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.