Struct asearch::Asearch[][src]

pub struct Asearch { /* fields omitted */ }
Expand description

Approximate pattern matching engine

Implementations

Create a new approximate pattern matching engine

Arguments

  • source - text which is searched for.

Do approximate pattern matching

Arguments

  • text - text which is searched.
  • ambig - Levenshtein distance.

Examples

// pattern: abcde
{
    let asearch = asearch::Asearch::new("abcde");

    assert!(asearch.find("abcde", 0));
    assert!(asearch.find("aBCDe", 0));
    assert!(asearch.find("abXcde", 1));
    assert!(asearch.find("ab?de", 1));
    assert!(asearch.find("abXXde", 2));
    assert!(!asearch.find("abXcde", 0));
    assert!(!asearch.find("ab?de", 0));
    assert!(!asearch.find("abde", 0));
    assert!(!asearch.find("abXXde", 1));
    assert!(asearch.find("abcde", 1));
    assert!(!asearch.find("abcd", 0));
    assert!(asearch.find("abcd", 1));
    assert!(asearch.find("bcde", 2));
}

// pattern: ab de
{
    let asearch = asearch::Asearch::new("ab de");
    assert!(asearch.find("abcde", 0));
    assert!(asearch.find("abccde", 0));
    assert!(asearch.find("abXXXXXXXde", 0));
    assert!(asearch.find("ababcccccxede", 1));
    assert!(!asearch.find("abcccccxe", 0));
}

// pattern: partial match
{
    let asearch = asearch::Asearch::new(" java ");

    assert!(asearch.find("javascript", 0));
    assert!(asearch.find("abcjavascript", 0));
    assert!(asearch.find("jabascript", 1));
    assert!(asearch.find("awesome jabascript", 1));
}

// pattern: unicode
{
    let asearch = asearch::Asearch::new("漢字文字列");

    assert!(asearch.find("漢字文字列", 0));
    assert!(!asearch.find("漢字の文字列", 0));
    assert!(asearch.find("漢字の文字列", 1));
    assert!(!asearch.find("漢字文字", 0));
    assert!(asearch.find("漢字文字", 1));
    assert!(!asearch.find("漢字文字烈", 0));
    assert!(asearch.find("漢字文字烈", 1));
    assert!(!asearch.find("漢和辞典", 2));
}

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.