Adds AnyOf

This commit is contained in:
Jesse Donat 2016-05-05 16:37:58 -05:00
parent d877f63521
commit 91cccc29e4
2 changed files with 30 additions and 0 deletions

28
any_of.go Normal file
View File

@ -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
}

View File

@ -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:
// //