Fix error in TolowerCamel when deal with strings with ID

This commit is contained in:
jonyhy96 2019-05-15 15:43:33 +08:00
parent e506e3ef73
commit 7a67297250
2 changed files with 5 additions and 0 deletions

View File

@ -68,6 +68,9 @@ func ToLowerCamel(s string) string {
if s == "" {
return s
}
if strings.Index(s, "ID") != -1 {
s = strings.Replace(s, "ID", "Id", -1)
}
if r := rune(s[0]); r >= 'A' && r <= 'Z' {
s = strings.ToLower(string(r)) + s[1:]
}

View File

@ -56,6 +56,8 @@ func TestToLowerCamel(t *testing.T) {
{"TestCase", "testCase"},
{"", ""},
{"AnyKind of_string", "anyKindOfString"},
{"UserID", "userId"},
{"ID", "id"},
}
for _, i := range cases {
in := i[0]