Adds every_of.go

This commit is contained in:
Jesse Donat 2016-05-05 16:40:31 -05:00
parent 91cccc29e4
commit 62800bb501
1 changed files with 28 additions and 0 deletions

28
every_of.go Normal file
View File

@ -0,0 +1,28 @@
package glob
// EveryOf represents a collection of globs
type EveryOf struct {
Globs Globs
}
// NewEveryOf returns a new EveryOf from a list of globs
func NewEveryOf(g ...Glob) EveryOf {
return EveryOf{Globs(g)}
}
// Add adds a glob to the EveryOf collection
func (a *EveryOf) Add(g Glob) {
a.Globs = append(a.Globs, g)
}
// Match checks every glob until one doesn't matches returning false.
// If every glob matches it returns true.
func (a EveryOf) Match(s string) bool {
for _, m := range a.Globs {
if !m.Match(s) {
return false
}
}
return true
}