diff --git a/any_of.go b/any_of.go new file mode 100644 index 0000000..1d7d8f2 --- /dev/null +++ b/any_of.go @@ -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 +} diff --git a/glob.go b/glob.go index 58f45c9..d1052ab 100644 --- a/glob.go +++ b/glob.go @@ -5,6 +5,8 @@ type Glob interface { Match(string) bool } +type Globs []Glob + // Compile creates Glob for given pattern and strings (if any present after pattern) as separators. // The pattern syntax is: //