fix: capitalize characters after -

feat: created ToLowerCamel() to not capitalize the first letter
This commit is contained in:
Joshua Chaitin-Pollak 2017-06-14 14:26:32 -04:00
parent efa75d0710
commit a2c126df64

View File

@ -5,10 +5,10 @@ import (
) )
// Converts a string to CamelCase // Converts a string to CamelCase
func ToCamel(s string) string { func ToCamelInitCase(s string, initCase bool) string {
s = strings.Trim(s, " ") s = strings.Trim(s, " ")
n := "" n := ""
capNext := true capNext := initCase
for _, v := range s { for _, v := range s {
if v >= 'A' && v <= 'Z' { if v >= 'A' && v <= 'Z' {
n += string(v) n += string(v)
@ -20,7 +20,7 @@ func ToCamel(s string) string {
n += string(v) n += string(v)
} }
} }
if v == '_' || v == ' ' { if v == '_' || v == ' ' || v == '-' {
capNext = true capNext = true
} else { } else {
capNext = false capNext = false
@ -28,3 +28,11 @@ func ToCamel(s string) string {
} }
return n return n
} }
func ToCamel(s string) string {
return ToCamelInitCase(s, true);
}
func ToLowerCamel(s string) string {
return ToCamelInitCase(s, false);
}