1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00
Files
Vince Prignano 56175c97b1 go: update vendor dependencies
Signed-off-by: Vince Prignano <vincepri@redhat.com>
2023-11-01 11:43:46 -07:00

36 lines
727 B
Go

package flect
import (
"strings"
"unicode"
)
// Underscore a string
// bob dylan --> bob_dylan
// Nice to see you! --> nice_to_see_you
// widgetID --> widget_id
func Underscore(s string) string {
return New(s).Underscore().String()
}
// Underscore a string
// bob dylan --> bob_dylan
// Nice to see you! --> nice_to_see_you
// widgetID --> widget_id
func (i Ident) Underscore() Ident {
out := make([]string, 0, len(i.Parts))
for _, part := range i.Parts {
var x strings.Builder
x.Grow(len(part))
for _, c := range part {
if unicode.IsLetter(c) || unicode.IsDigit(c) {
x.WriteRune(c)
}
}
if x.Len() > 0 {
out = append(out, x.String())
}
}
return New(strings.ToLower(strings.Join(out, "_")))
}