goldsmith/filter_stack.go

34 lines
559 B
Go
Raw Normal View History

package goldsmith
2024-03-04 05:39:08 +00:00
type (
filterEntry struct {
filter Filter
index int
}
2024-03-04 05:39:08 +00:00
filterStack []filterEntry
)
func (self *filterStack) accept(file *File) bool {
for _, entry := range *self {
if entry.index >= file.index && !entry.filter.Accept(file) {
return false
}
}
return true
}
func (self *filterStack) push(filter Filter, index int) {
*self = append(*self, filterEntry{filter, index})
}
func (self *filterStack) pop() {
count := len(*self)
if count == 0 {
panic("attempted to pop empty filter stack")
}
*self = (*self)[:count-1]
}