Files
descrybe/apps/api/internal/processing/title_spacing.go
T
2026-08-17 01:30:28 +02:00

23 lines
738 B
Go

package processing
import (
"regexp"
"strings"
)
// Glue between a lowercase letter and an UPPERCASE model token
// (e.g. "hladilnikGSXV80PZLE" → "hladilnik GSXV80PZLE").
// Digits are excluded from the left side so "GSXV80PZLE" is not split at "0P".
var reGlueUpperModel = regexp.MustCompile(`(\p{Ll})([\p{Lu}][\p{Lu}\p{Nd}]{2,})`)
// ensureReadableTitleSpacing inserts missing spaces before glued model codes and
// collapses whitespace. Safe for already-spaced retail titles.
func ensureReadableTitleSpacing(title string) string {
title = strings.TrimSpace(title)
if title == "" || title == "<nil>" {
return title
}
out := reGlueUpperModel.ReplaceAllString(title, "$1 $2")
return strings.Join(strings.Fields(out), " ")
}