package scan import "strings" // TitleMatcher returns true if a title should be kept. type TitleMatcher func(title string) bool // NewTitleMatcher builds a case-insensitive positive/negative matcher. // At least one positive must match (or positives empty) AND zero negatives. func NewTitleMatcher(f TitleFilter) TitleMatcher { pos := lower(f.Positive) neg := lower(f.Negative) return func(title string) bool { lt := strings.ToLower(title) hasPos := len(pos) == 0 for _, p := range pos { if strings.Contains(lt, p) { hasPos = true break } } if !hasPos { return false } for _, n := range neg { if strings.Contains(lt, n) { return false } } return true } } func lower(ss []string) []string { out := make([]string, 0, len(ss)) for _, s := range ss { out = append(out, strings.ToLower(s)) } return out }