feat: implement remove command with sequential removals

This commit is contained in:
Rogee
2025-10-29 18:59:55 +08:00
parent 446bd46b95
commit f66c59fd57
31 changed files with 986 additions and 110 deletions

36
internal/remove/engine.go Normal file
View File

@@ -0,0 +1,36 @@
package remove
import "strings"
// Result captures the outcome of applying sequential removals to a candidate.
type Result struct {
Candidate Candidate
ProposedName string
Matches map[string]int
Changed bool
}
// ApplyTokens removes each token sequentially from the candidate's basename.
func ApplyTokens(candidate Candidate, tokens []string) Result {
current := candidate.BaseName
matches := make(map[string]int, len(tokens))
for _, token := range tokens {
if token == "" {
continue
}
count := strings.Count(current, token)
if count == 0 {
continue
}
current = strings.ReplaceAll(current, token, "")
matches[token] += count
}
return Result{
Candidate: candidate,
ProposedName: current,
Matches: matches,
Changed: current != candidate.BaseName,
}
}