filter

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fuzzy

func Fuzzy(text, query string, c Case) []int

Fuzzy reports whether every rune in query appears in text in order (but not necessarily contiguously). It returns the matched rune indexes, or nil if the query does not match. Case sensitivity is controlled by c using the same semantics as Term.Match: SmartCase is case-insensitive unless query contains uppercase.

When multiple match positions exist, Fuzzy prefers the tightest (shortest-span) match using a three-pass algorithm:

  1. Forward pass to confirm a match exists.
  2. Backward pass to find the tightest window.
  3. Forward pass over that window to collect exact indexes.

func FuzzyBytes

func FuzzyBytes(text string, indexes []int) [][2]int

FuzzyBytes converts matched rune indexes (from Fuzzy) into byte offset pairs within text. Each pair [start, end) covers one matched rune. Returns nil when indexes is empty.

Types

type Case

type Case uint8

Case controls case sensitivity for matching.

const (
	// SmartCase is case-insensitive unless the term contains uppercase.
	SmartCase Case = iota
	// CaseSensitive always matches case exactly.
	CaseSensitive
	// CaseInsensitive always ignores case.
	CaseInsensitive
)

type Term

type Term struct {
	Text   string
	Prefix bool // ^ anchor
	Suffix bool // $ anchor
	Negate bool // ! invert
	Case   Case
}

Term represents a parsed search term with optional modifiers.

func Parse

func Parse(f string) Term

Parse parses a filter string into a Term.

Supported modifiers:

  • ! at the start negates the match
  • ^ anchors to the start of the text
  • $ anchors to the end of the text

Case sensitivity uses smart case: case-insensitive unless the term contains an uppercase letter.

func (Term) Match

func (t Term) Match(text string) bool

Match reports whether text matches the term.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL