matches

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package matches provides utilities for searching and matching things.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PathMatcher

type PathMatcher interface {
	// Match checks if the path matches and returns true if it does
	Match(path string) (bool, error)
}

PathMatcher is used to determine if a file system path matches.

type RegexList

type RegexList struct {
	// contains filtered or unexported fields
}

A list of compiled regular expressions that can be used to match things.

func NewRegexList

func NewRegexList(expressions []string) (*RegexList, error)

Create a new RegexList that compiles the given regular expressions.

func (*RegexList) Matches

func (l *RegexList) Matches(needles []string) []string

Returns the slice of needles that matched any of the compiled regular expressions.

func (*RegexList) MatchesAll

func (l *RegexList) MatchesAll(needle string) bool

Returns true if the needle matches all of the compiled regular expressions.

func (*RegexList) MatchesAny

func (l *RegexList) MatchesAny(needle string) bool

Returns true if the needle matches any of the compiled regular expressions.

type RegexListCompileErr

type RegexListCompileErr struct {
	Input string
	Index int
	Err   error
}

func (*RegexListCompileErr) Error

func (e *RegexListCompileErr) Error() string

type RegexPathMatcher

type RegexPathMatcher struct {
	// contains filtered or unexported fields
}

RegexPathMatcher will match a file system path against a set of regular expressions.

func NewRegexPathMatcher

func NewRegexPathMatcher(expressions []string) (*RegexPathMatcher, error)

Create a new RegexPathMatcher using the regular expression patterns.

func (*RegexPathMatcher) Match

func (r *RegexPathMatcher) Match(path string) (bool, error)

type RegexScanner

type RegexScanner struct {
	// contains filtered or unexported fields
}

RegexScanner is used to read from an io.Reader line by line and then tries to match the line against a set of regular expressions.

func (*RegexScanner) Add

func (r *RegexScanner) Add(key string, expression string, foundFn RegexScannerFoundMatches) error

Register a regular expression that will try and find matches when the Process function is called NOTE: To match case-insensitive add the prefix (?i) to the regular expression.

func (*RegexScanner) Process

func (r *RegexScanner) Process(rd io.Reader) (RegexScannerResult, error)

Read line by line from the io.Reader and try and find matching regular expressions. The read line will be written to any writter set by SetOut method.

func (*RegexScanner) SetOut

func (r *RegexScanner) SetOut(w io.Writer)

Set the io.Writer that will be used to write any line read from the io.Reader during the Process method. Useful for debugging.

type RegexScannerFoundMatches

type RegexScannerFoundMatches func(key string, line string, lineNumber int, matches []string) error

Function that will be called when a regular expression found some matches.

type RegexScannerResult

type RegexScannerResult map[string][]string

Result from the Process function. A map of the key to matching substrings. NOTE: The result will always contain the last found match for a key (meaning the map is updated on each find).

type ShellPatternPathMatcher

type ShellPatternPathMatcher struct {
	// contains filtered or unexported fields
}

ShellPatternPathMatcher will match a file system path against a set of shell patterns. See https://pkg.go.dev/path/filepath#Match for details.

func NewShellPatternPathMatcher

func NewShellPatternPathMatcher(patterns []string) *ShellPatternPathMatcher

Create a new ShellPatternPathMatcher using the shell patterns.

func (*ShellPatternPathMatcher) Match

func (s *ShellPatternPathMatcher) Match(path string) (bool, error)

Jump to

Keyboard shortcuts

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