textsearch

package
v2.22.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMatch is returned when no match is found.
	ErrNoMatch = errors.New("no match found")
	// ErrEmptyPattern is returned when pattern is empty.
	ErrEmptyPattern = errors.New("empty pattern")
)
View Source
var DefaultGrepOptions = GrepOptions{
	IsRegexp: true,
	Before:   2,
	After:    2,
}

Functions

This section is empty.

Types

type GrepOptions

type GrepOptions struct {
	IsRegexp bool
	Before   int
	After    int
	Offset   int
	Limit    int
	Matcher  Matcher
}

GrepOptions represents grep options. If IsRegexp is true, the pattern is treated as a regular expression. Before and After are the number of lines before and after the matched line.

type Match

type Match struct {
	Line       string
	LineNumber int
	StartLine  int
}

Match contains a matching line and its surrounding text.

func Grep

func Grep(dat []byte, pattern string, opts GrepOptions) ([]*Match, error)

Grep reads data and returns lines that match the given pattern. If opts is nil, default options will be used.

func GrepWithCount

func GrepWithCount(dat []byte, pattern string, opts GrepOptions) ([]*Match, int, error)

GrepWithCount reads data and returns matching snippets and the total match count.

type Matcher

type Matcher interface {
	// Match returns true if the given line matches.
	Match(line string) bool
}

Matcher is the interface for matching lines.

type WindowResult

type WindowResult struct {
	Matches    []*Match
	HasMore    bool
	NextOffset int
}

WindowResult contains a bounded snippet window and its continuation state.

func GrepWindow

func GrepWindow(dat []byte, pattern string, opts GrepOptions) (*WindowResult, error)

GrepWindow returns at most opts.Limit snippets after opts.Offset matches. It stops once it can determine whether a continuation page exists.

Jump to

Keyboard shortcuts

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