grep

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: GPL-3.0 Imports: 6 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 matched")
	// ErrEmptyPattern is returned when pattern is empty.
	ErrEmptyPattern = errors.New("empty pattern")
)

Functions

This section is empty.

Types

type Match

type Match struct {
	Line       string
	LineNumber int
	StartLine  int
}

Match contains matched line number and line content.

func Grep

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

Grep read file and return matched lines. If opts is nil, default options will be used.

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 Options

type Options struct {
	IsRegexp bool
	Before   int
	After    int
	Matcher  Matcher
}

Options 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.

Jump to

Keyboard shortcuts

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