package rds

import "strings"

// normalizePS produces exactly 8 ASCII bytes for the RDS Program Service name.
// Non-ASCII runes are replaced with space to avoid mid-rune truncation.
func normalizePS(ps string) string {
	ps = strings.ToUpper(ps)
	clean := toASCII(ps)
	if len(clean) > 8 {
		clean = clean[:8]
	}
	if len(clean) < 8 {
		clean = clean + strings.Repeat(" ", 8-len(clean))
	}
	return clean
}

// normalizeRT produces up to 64 ASCII bytes for RDS RadioText.
func normalizeRT(rt string) string {
	clean := toASCII(rt)
	if len(clean) > 64 {
		clean = clean[:64]
	}
	return clean
}

// toASCII replaces any non-ASCII byte with space.
// RDS uses EBU Latin which is close to ASCII for the printable range.
func toASCII(s string) string {
	b := []byte(s)
	for i, c := range b {
		if c < 0x20 || c > 0x7E {
			b[i] = ' '
		}
	}
	return string(b)
}
