mirror of https://github.com/gobwas/glob.git
Adds AnyOf
This commit is contained in:
parent
d877f63521
commit
91cccc29e4
|
@ -0,0 +1,28 @@
|
||||||
|
package glob
|
||||||
|
|
||||||
|
// AnyOf represents a collection of globs
|
||||||
|
type AnyOf struct {
|
||||||
|
Globs Globs
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAnyOf returns a new AnyOf from a list of globs
|
||||||
|
func NewAnyOf(g ...Glob) AnyOf {
|
||||||
|
return AnyOf{Globs(g)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add adds a glob to the AnyOf collection
|
||||||
|
func (a *AnyOf) Add(g Glob) {
|
||||||
|
a.Globs = append(a.Globs, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Match checks every glob until one matches returning true.
|
||||||
|
// If none matches it returns false.
|
||||||
|
func (a AnyOf) Match(s string) bool {
|
||||||
|
for _, m := range a.Globs {
|
||||||
|
if m.Match(s) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
2
glob.go
2
glob.go
|
@ -5,6 +5,8 @@ type Glob interface {
|
||||||
Match(string) bool
|
Match(string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Globs []Glob
|
||||||
|
|
||||||
// Compile creates Glob for given pattern and strings (if any present after pattern) as separators.
|
// Compile creates Glob for given pattern and strings (if any present after pattern) as separators.
|
||||||
// The pattern syntax is:
|
// The pattern syntax is:
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue