Merge pull request #3 from jbcpollak/master
added ToLowerCamel(), capitalize characters after -
This commit is contained in:
commit
adbbf08fa6
14
camel.go
14
camel.go
@ -5,10 +5,10 @@ import (
|
||||
)
|
||||
|
||||
// Converts a string to CamelCase
|
||||
func ToCamel(s string) string {
|
||||
func ToCamelInitCase(s string, initCase bool) string {
|
||||
s = strings.Trim(s, " ")
|
||||
n := ""
|
||||
capNext := true
|
||||
capNext := initCase
|
||||
for _, v := range s {
|
||||
if v >= 'A' && v <= 'Z' {
|
||||
n += string(v)
|
||||
@ -20,7 +20,7 @@ func ToCamel(s string) string {
|
||||
n += string(v)
|
||||
}
|
||||
}
|
||||
if v == '_' || v == ' ' {
|
||||
if v == '_' || v == ' ' || v == '-' {
|
||||
capNext = true
|
||||
} else {
|
||||
capNext = false
|
||||
@ -28,3 +28,11 @@ func ToCamel(s string) string {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func ToCamel(s string) string {
|
||||
return ToCamelInitCase(s, true);
|
||||
}
|
||||
|
||||
func ToLowerCamel(s string) string {
|
||||
return ToCamelInitCase(s, false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user