strcase/camel.go
Joshua Chaitin-Pollak a2c126df64 fix: capitalize characters after -
feat: created ToLowerCamel() to not capitalize the first letter
2017-06-14 14:26:32 -04:00

39 lines
636 B
Go

package strcase
import (
"strings"
)
// Converts a string to CamelCase
func ToCamelInitCase(s string, initCase bool) string {
s = strings.Trim(s, " ")
n := ""
capNext := initCase
for _, v := range s {
if v >= 'A' && v <= 'Z' {
n += string(v)
}
if v >= 'a' && v <= 'z' {
if capNext {
n += strings.ToUpper(string(v))
} else {
n += string(v)
}
}
if v == '_' || v == ' ' || v == '-' {
capNext = true
} else {
capNext = false
}
}
return n
}
func ToCamel(s string) string {
return ToCamelInitCase(s, true);
}
func ToLowerCamel(s string) string {
return ToCamelInitCase(s, false);
}