Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Glob ¶
type Glob struct {
OriginalPattern string
IgnoreCase bool
FS filesystem.Filesystem
// contains filtered or unexported fields
}
Glob is the main globbing engine. It holds the original pattern and configuration for a globbing operation.
An instance is created with NewGlob, which allows for advanced configuration, such as setting a custom filesystem or enabling case-insensitive matching.
func NewGlob ¶
func NewGlob(pattern string, fs filesystem.Filesystem, opts ...GlobOption) *Glob
NewGlob creates and returns a new Glob engine for the given pattern. It uses the provided filesystem `fs` for all file operations. If `fs` is nil, it defaults to the host operating system's filesystem.
Functional options (GlobOption) can be provided to customize the globber's behavior, such as enabling case-insensitive matching with WithIgnoreCase.
func (*Glob) Expand ¶
Expand executes the glob pattern and returns all matching file paths. It is the primary method for retrieving results from a configured Glob instance. The function returns an empty, non-nil slice if no matches are found.
func (*Glob) ExpandNames
deprecated
type GlobOption ¶
type GlobOption func(*Glob)
A GlobOption configures a Glob instance. It's a functional option type used with NewGlob.
func WithIgnoreCase ¶
func WithIgnoreCase(v bool) GlobOption
WithIgnoreCase returns a GlobOption that sets the globber to perform case-insensitive matching. On Windows, literal (non-wildcard) path segments are case-insensitive by default. This option forces wildcards and all other patterns to also ignore case.
type RegexOrString ¶
type RegexOrString struct {
// CompiledRegex is the compiled regular expression if the pattern segment contains wildcards.
CompiledRegex *regexp.Regexp
// IsRegex indicates if CompiledRegex is used for matching.
IsRegex bool
// LiteralPattern is the original glob pattern segment if it's treated as a literal.
LiteralPattern string
// IgnoreCase indicates if matching should be case-insensitive for literal patterns.
IgnoreCase bool
// OriginalRegexPattern stores the regex string pattern before compilation (for debugging or special checks).
OriginalRegexPattern string
}
RegexOrString is a helper struct that holds either a compiled regular expression or a literal string for efficient pattern matching. It is used internally to optimize matching by avoiding regex compilation for simple patterns.
func (*RegexOrString) IsMatch ¶
func (ros *RegexOrString) IsMatch(input string) bool
IsMatch checks if the input string matches this RegexOrString. For regex patterns, it uses the compiled regex. For literal patterns, it performs a string comparison, respecting IgnoreCase.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package filesystem provides abstractions for filesystem operations to enable easier testing and mocking of file system interactions.
|
Package filesystem provides abstractions for filesystem operations to enable easier testing and mocking of file system interactions. |