Documentation ¶
Overview ¶
Package glob provides configurable globbing and matching algorithms. It can be used to for glob-style matching on string slices.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadPattern = errors.New("syntax error in pattern")
ErrBadPattern indicates a globbing pattern was malformed.
Functions ¶
func GlobStrings ¶
GlobStrings returns all expanded paths from list matching pattern or nil if there are no matches. This function calls the corresponding method of a Globber with default Config and is equivalent to:
glob.New(glob.Default()).GlobStrings(list, pattern)
Types ¶
type Config ¶
type Config struct { Separator byte // Separator separates path element Star byte // Star wildcard matching zero or more characters Quest byte // Quest wildcard matching one character Range byte // Range start matches ranges one character from a specified range RangeEnd byte // RangeEnd ends a Range. Ranges of characters can be specified with '-' e.g. [0-9] RangeNeg byte // RangeNeg negates the Range e.g. [^a-z] GlobStar bool // GlobStar enables multiple Stars to match across directory boundaries }
Config represents Globber options. It can be used to change the supported pattern control characters and Separator as well as enable GlobStar behaviour.
type Globber ¶
type Globber struct {
// contains filtered or unexported fields
}
Globber provides configurable globbing and matching algorithms.
func (*Globber) GlobStrings ¶
GlobStrings returns all expanded paths from list matching pattern or nil if there are no matches. The syntax of pattern is the same as in Match. The control characters of the pattern and GlobStar matching behaviour can be configured in Config. The given list must be sorted in ascending order. New matches are added in lexicographical order.
func (*Globber) Match ¶
Match returns true if name matches the shell file name pattern. The control characters can be changed with glob.Config The pattern syntax is:
pattern: { term } term: Star matches any sequence of non-Separator characters Star+ matches across directory Separators if GlobStar is enabled Quest matches any single non-Separator character Range [ RangeNeg ] { character-range } RangeEnd character class (must be non-empty) c matches character c (c != '*', '?', '\\', '[') '\\' c matches character c character-range: c matches character c (c != '\\', '-', RangeEnd) '\\' c matches character c lo '-' hi matches character c for lo <= c <= hi
Match requires pattern to match all of name, not just a substring. The only possible returned error is ErrBadPattern, when pattern is malformed.
On Windows, escaping is disabled. Instead, '\\' is treated as path separator.