matcher

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package matcher scans a file line-by-line for occurrences of one or more patterns, returning hits with line/column information.

Two modes:

  • literal (default): byte-fast substring search via strings.Index, optionally requiring a UTF-8 word boundary around the match. A search for `технология` doesn't fire inside `вижутехнологияя` thanks to the boundary check using utf8.DecodeRune.
  • regex (Options.Regex): each pattern is compiled with regexp.Compile; case-insensitive mode prepends `(?i:...)` to the pattern. Word boundary is ignored — the user controls it via `\b`.

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("matcher: file skipped (binary or over-long line)")

ErrSkip signals that a file should be silently skipped rather than failing the whole scan — it is binary, or has a line longer than the scanner's buffer (minified bundles, lock files, source maps). Callers (grep, xref) count these and continue.

Functions

This section is empty.

Types

type Hit

type Hit struct {
	Pattern string // which input pattern produced the hit
	Line    int
	Col     int
	Text    string
}

func ScanFile

func ScanFile(path string, opts Options) ([]Hit, []string, error)

ScanFile opens path and returns hits for every configured pattern, plus the full set of lines read so callers can extract surrounding context without re-reading the file.

type Options

type Options struct {
	Patterns  []string // one or more patterns to look for
	Case      bool     // true: case-sensitive
	WordBound bool     // true: require non-word boundary (literal mode only)
	Regex     bool     // true: patterns are Go regexp; WordBound is ignored
}

Jump to

Keyboard shortcuts

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