Skip to content
FutureBlitz

    Install

    Import std.text.fuzzy

    std.text.fuzzy

    Fuzzy matching of text, as fzf does it.

    A pattern matches text that has its characters in order, with anything between them, and the best way to place them scores most: characters that follow each other, and ones at the start of a word, after a space, a /, or a _, or a capital in camelCase, score more, and gaps between them less. A pattern without capitals ignores case. Positions are byte positions, as a String's are.

    std/text/fuzzy.fb

    Types

    FuzzyMatch struct

    Public Struct FuzzyMatch

    What a fuzzy match found: its Score, higher for a better match, and the byte Positions of the text's characters that the pattern's matched, in order.

    Examples

    Local found = Fuzzy.Match("fb", "foobar")
    Expect(found != Null)
    If found == Null Then Return
    Expect(found.Score > 0 && found.Positions == [0, 3])

    std/text/fuzzy.fb, line 42

    • Public ReadOnly Field Score: Int field #

      How well the pattern matched: higher for a better match.

    • Public ReadOnly Field Positions: Int[] field #

      The byte positions of the characters the pattern's matched, in order.

    Fuzzy class

    Public Class Fuzzy

    Fuzzy matching's operations.

    Examples

    Expect(Fuzzy.Match("fb", "foobar")?.Positions == [0, 3])
    Expect(Fuzzy.Match("fb", "xyz") == Null)
    Expect(Fuzzy.Rank("fb", ["xyz", "foobar"]) == ["foobar"])

    std/text/fuzzy.fb, line 58

    • Public Static Method Match(pattern: String, text: String): FuzzyMatch? static method #

      The best match of pattern in text, or Null when text doesn't have pattern's characters in order. An empty pattern matches anything, scoring 0.

    • Public Static Method Score(pattern: String, text: String): Int? static method #

      pattern's score in text, or Null when it doesn't match.

    • Public Static Method Rank(pattern: String, candidates: String[]): String[] static method #

      The candidates that match pattern, the best first: by score, then the shorter, then in the order given.

    Report an issue with this page or with FutureBlitz on GitHub.