refactor(scanner): make tag value splitting position-based

Replaces the ZWSP substitution trick with index-based cutting, in
preparation for artist split exceptions, which need match positions.
This commit is contained in:
Deluan 2026-07-01 21:24:43 -04:00
parent b405252f51
commit 84e5bd3047

View File

@ -9,7 +9,6 @@ import (
"sync"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model/criteria"
"github.com/navidrome/navidrome/resources"
@ -43,18 +42,21 @@ func (c TagConf) SplitTagValue(values []string) []string {
var result []string
for _, tag := range values {
// Replace all occurrences of any separator with the zero-width space.
tag = c.SplitRx.ReplaceAllString(tag, consts.Zwsp)
// Split by the zero-width space and trim each substring.
parts := strings.SplitSeq(tag, consts.Zwsp)
for part := range parts {
result = append(result, strings.TrimSpace(part))
}
result = append(result, c.splitValue(tag)...)
}
return result
}
func (c TagConf) splitValue(tag string) []string {
var parts []string
start := 0
for _, sep := range c.SplitRx.FindAllStringIndex(tag, -1) {
parts = append(parts, strings.TrimSpace(tag[start:sep[0]]))
start = sep[1]
}
return append(parts, strings.TrimSpace(tag[start:]))
}
type TagType string
const (