goldsmith/filter_util.go

34 lines
580 B
Go
Raw Normal View History

package goldsmith
type filterEntry struct {
filter Filter
index int
}
type filterStack []filterEntry
2024-02-20 00:26:41 +00:00
func (self *filterStack) accept(file File) bool {
2024-02-20 06:20:10 +00:00
cf := file.(*contextFile)
for _, entry := range *self {
2024-02-20 06:20:10 +00:00
if entry.index >= cf.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]
}