Merge pull request #1 from takuoki/fix_ToLowerCamel

fix ToLowerCamel
This commit is contained in:
Takuo Oki 2018-06-01 17:42:21 +09:00 committed by GitHub
commit d4019beef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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]