Merge pull request #1 from takuoki/first_upper_case
improve first upper case for ToLowerCamel
This commit is contained in:
commit
e136f613ee
6
camel.go
6
camel.go
@ -38,5 +38,11 @@ func ToCamel(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ToLowerCamel(s string) string {
|
func ToLowerCamel(s string) string {
|
||||||
|
if s == "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
if r := rune(s[0]); r >= 'A' && r <= 'Z' {
|
||||||
|
s = strings.ToLower(string(r)) + s[1:]
|
||||||
|
}
|
||||||
return toCamelInitCase(s, false)
|
return toCamelInitCase(s, false)
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,9 @@ func TestToCamel(t *testing.T) {
|
|||||||
func TestToLowerCamel(t *testing.T) {
|
func TestToLowerCamel(t *testing.T) {
|
||||||
cases := [][]string{
|
cases := [][]string{
|
||||||
[]string{"foo-bar", "fooBar"},
|
[]string{"foo-bar", "fooBar"},
|
||||||
|
[]string{"TestCase", "testCase"},
|
||||||
|
[]string{"", ""},
|
||||||
|
[]string{"AnyKind of_string", "anyKindOfString"},
|
||||||
}
|
}
|
||||||
for _, i := range cases {
|
for _, i := range cases {
|
||||||
in := i[0]
|
in := i[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user