fix ToLowerCamel

This commit is contained in:
takuoki 2018-06-01 17:35:02 +09:00
parent 6b1e2b920d
commit 727535a5a9
2 changed files with 8 additions and 2 deletions

View File

@ -10,9 +10,13 @@ func toCamelInitCase(s string, initCase bool) string {
s = strings.Trim(s, " ")
n := ""
capNext := initCase
for _, v := range s {
for i, v := range s {
if v >= 'A' && v <= 'Z' {
n += string(v)
if !initCase && i == 0 {
n += strings.ToLower(string(v))
} else {
n += string(v)
}
}
if v >= '0' && v <= '9' {
n += string(v)

View File

@ -29,6 +29,8 @@ func TestToCamel(t *testing.T) {
func TestToLowerCamel(t *testing.T) {
cases := [][]string{
[]string{"foo-bar", "fooBar"},
[]string{"TestCase", "testCase"},
[]string{"AnyKind of_string", "anyKindOfString"},
}
for _, i := range cases {
in := i[0]