Fix error in TolowerCamel when deal with strings with ID
This commit is contained in:
parent
e506e3ef73
commit
7a67297250
3
camel.go
3
camel.go
@ -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:]
|
||||
}
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user