misc-utils.go: corretti alcuni difetti, in particolare in OnEmpty()

This commit is contained in:
Celestino Amoroso 2025-10-24 14:46:14 +02:00
parent bf4e35ea0d
commit 49c3087114

View File

@ -20,7 +20,7 @@ func NewEnglishPrinter() *message.Printer {
return message.NewPrinter(language.English) return message.NewPrinter(language.English)
} }
func ExitErrorf(rc int, format string, args ...interface{}) { func ExitErrorf(rc int, format string, args ...any) {
fmt.Fprintf(os.Stderr, format+"\n", args...) fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(rc) os.Exit(rc)
} }
@ -31,7 +31,7 @@ func ExitMessagef(rc int, format string, args ...interface{}) {
} }
func OnStringIndex(index uint, values ...string) (value string) { func OnStringIndex(index uint, values ...string) (value string) {
if index >= 0 && index < uint(len(values)) { if index < uint(len(values)) {
value = values[index] value = values[index]
} }
return return
@ -42,12 +42,13 @@ func OnEmpty(s string, altValues ...string) (value string) {
for _, altValue := range altValues { for _, altValue := range altValues {
if len(altValue) > 0 { if len(altValue) > 0 {
value = altValue value = altValue
break
} }
} }
} else { } else {
value = s value = s
} }
return s return value
} }
func OnCond(cond bool, trueValue, falseValue string) string { func OnCond(cond bool, trueValue, falseValue string) string {