pattern

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseDirMatcher

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

BaseDirMatcher is a pattern that matches any path under a given base directory.

func NewBaseDirMatcher

func NewBaseDirMatcher(basePath string) (*BaseDirMatcher, error)

NewBaseDirMatcher creates a new BaseDirMatcher with the given base path.

func (*BaseDirMatcher) Matches

func (p *BaseDirMatcher) Matches(str string) bool

Matches checks if the given string matches the base directory pattern.

func (*BaseDirMatcher) String

func (p *BaseDirMatcher) String() string

String returns the string representation of the base directory pattern.

type ExactMatcher

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

ExactMatcher is a pattern that matches a string exactly.

func NewExactMatcher

func NewExactMatcher(pattern string) (*ExactMatcher, error)

NewExactMatcher creates a new ExactMatcher with the given pattern.

func (*ExactMatcher) Matches

func (p *ExactMatcher) Matches(str string) bool

Matches checks if the given string matches the exact pattern.

func (*ExactMatcher) String

func (p *ExactMatcher) String() string

String returns the string representation of the exact pattern.

type GlobMatcher

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

GlobMatcher is a pattern that uses glob syntax to match strings. When using this pattern for paths, make sure to use '/' as the path separator to avoid issues with OS-specific path separators.

func NewGlobPattern

func NewGlobPattern(pattern string) (*GlobMatcher, error)

NewGlobPattern creates a new GlobMatcher with the given pattern. If the pattern is invalid, it returns an error.

func (*GlobMatcher) Matches

func (p *GlobMatcher) Matches(str string) bool

Matches checks if the given string matches the glob pattern.

func (*GlobMatcher) String

func (p *GlobMatcher) String() string

String returns the string representation of the glob pattern.

type Matcher

type Matcher interface {
	// Matches checks if the given string matches the pattern.
	Matches(string) bool
	// String returns the string representation of the pattern.
	String() string
}

Matcher is an interface that defines a method for matching strings against a specific pattern. It can be implemented by different types of patterns, such as glob patterns, regular expressions, or base directory patterns.

func ParseNamePattern

func ParseNamePattern(pattern string) (Matcher, error)

ParseNamePattern parses a pattern string and returns a Matcher. It recognizes glob patterns (with "glob:" prefix), regular expressions (with "regex:" or "regexp:" prefix), and exact string matches (without any prefix).

func ParsePathPattern

func ParsePathPattern(pattern string) (Matcher, error)

ParsePathPattern parses a pattern string and returns a Matcher. It recognizes glob patterns (with "glob:" prefix), regular expressions (with "regex:" or "regexp:" prefix), and base directory patterns (without any prefix). It is important to note that when using this pattern for paths, you should use '/' as the path separator to avoid issues with OS-specific path separators.

type Matchers

type Matchers []Matcher

func (Matchers) Matches

func (m Matchers) Matches(str string) bool

Matches checks if any of the matchers match the given string.

func (Matchers) String

func (m Matchers) String() string

String returns a string representation of all matchers.

type RegexpMatcher

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

RegexpMatcher is a pattern that uses regular expressions to match strings. When using this pattern for paths, make sure to use '/' as the path separator to avoid issues with OS-specific path separators.

func NewRegexpMatcher

func NewRegexpMatcher(pattern string) (*RegexpMatcher, error)

NewRegexpMatcher creates a new RegexpMatcher with the given pattern. If the pattern is invalid, it returns an error.

func (*RegexpMatcher) Matches

func (p *RegexpMatcher) Matches(str string) bool

Matches checks if the given string matches the regexp pattern.

func (*RegexpMatcher) String

func (p *RegexpMatcher) String() string

String returns the string representation of the regexp pattern.

Jump to

Keyboard shortcuts

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