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])-
How well the pattern matched: higher for a better match.
-
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"])-
The best match of
patternintext, or Null whentextdoesn't havepattern's characters in order. An emptypatternmatches anything, scoring 0. -
pattern's score intext, or Null when it doesn't match. -
The
candidatesthat matchpattern, the best first: by score, then the shorter, then in the order given.
Report an issue with this page or with FutureBlitz on GitHub.