package services import "strings" // isGlobPattern reports whether s contains wildcard characters (* or ?). func isGlobPattern(s string) bool { return strings.ContainsAny(s, "*?") } // matchGlob reports whether text matches the glob pattern. // '*' matches any sequence of characters (including empty). // '?' matches exactly one character. // Both pattern and text must already be normalized (e.g. lowercased, separators removed) // by the caller before passing to this function. func matchGlob(pattern, text string) bool { p, t := 0, 0 lastStar, lastMatch := -1, 0 for t < len(text) { if p < len(pattern) && (pattern[p] == '?' || pattern[p] == text[t]) { p++ t++ } else if p < len(pattern) && pattern[p] == '*' { lastStar = p lastMatch = t p++ } else if lastStar >= 0 { p = lastStar + 1 lastMatch++ t = lastMatch } else { return false } } for p < len(pattern) && pattern[p] == '*' { p++ } return p == len(pattern) } // ignoreIndex holds both exact and pattern-based ignore rules. type ignoreIndex struct { exact map[string]struct{} // normalized exact partnumbers patterns []string // normalized glob patterns } // isIgnored checks whether a normalized partnumber key is ignored (exact or pattern). func (idx *ignoreIndex) isIgnored(normalizedPN string) bool { if normalizedPN == "" { return false } if _, ok := idx.exact[normalizedPN]; ok { return true } for _, pat := range idx.patterns { if matchGlob(pat, normalizedPN) { return true } } return false }