kilo/vendor/github.com/gobuffalo/flect/underscore.go
leonnicolas 36643b77b4
Use apiextension v1
- upgrade from apiextension v1beta1 to v1
 - generate yaml manifest for crd intead of applying it at runtime
  - users will have to apply the manifest with kubectl
 - kg and kgctl log an error if the crd is not present
 - now validation should actually work

Signed-off-by: leonnicolas <leonloechner@gmx.de>
2021-06-14 12:59:33 +02:00

36 lines
715 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, "_")))
}