kubekey/vendor/github.com/gobuffalo/flect/camelize.go
github-actions[bot] 4f4b7333b8
Some checks failed
SyncVendor / sync vendor (push) Has been cancelled
Add vendor directory (#2450)
Co-authored-by: ks-ci-bot <ci-bot@kubesphere.io>
Signed-off-by: joyceliu <joyceliu@yunify.com>
2024-11-05 12:04:06 +08:00

45 lines
835 B
Go

package flect
import (
"strings"
"unicode"
)
// Camelize returns a camelize version of a string
// bob dylan = bobDylan
// widget_id = widgetID
// WidgetID = widgetID
func Camelize(s string) string {
return New(s).Camelize().String()
}
// Camelize returns a camelize version of a string
// bob dylan = bobDylan
// widget_id = widgetID
// WidgetID = widgetID
func (i Ident) Camelize() Ident {
var out []string
for i, part := range i.Parts {
var x string
var capped bool
for _, c := range part {
if unicode.IsLetter(c) || unicode.IsDigit(c) {
if i == 0 {
x += string(unicode.ToLower(c))
continue
}
if !capped {
capped = true
x += string(unicode.ToUpper(c))
continue
}
x += string(c)
}
}
if x != "" {
out = append(out, x)
}
}
return New(strings.Join(out, ""))
}