openmeter / pkg /strcase /strcase.go
Leon4gr45's picture
Upload folder using huggingface_hub (part 10)
6380833 verified
Raw
History Blame Contribute Delete
633 Bytes
package strcase
import (
"strings"
"unicode"
)
func SnakeToCamel(snake string) string {
isToUpper := false
camel := ""
for i, ch := range snake {
if ch == '_' {
isToUpper = true
} else {
if isToUpper && i > 0 {
camel += string(unicode.ToUpper(ch))
isToUpper = false
} else {
camel += string(ch)
}
}
}
return camel
}
func CamelToSnake(camel string) string {
var snake strings.Builder
for i, ch := range camel {
if unicode.IsUpper(ch) {
if i > 0 {
snake.WriteRune('_')
}
snake.WriteRune(unicode.ToLower(ch))
} else {
snake.WriteRune(ch)
}
}
return snake.String()
}