Fix acronyms for camel case
This commit is contained in:
parent
21f80d9b9a
commit
198ca931c7
5
acronyms.go
Normal file
5
acronyms.go
Normal file
@ -0,0 +1,5 @@
|
||||
package strcase
|
||||
|
||||
var uppercaseAcronym = map[string]bool{
|
||||
"ID": true,
|
||||
}
|
6
camel.go
6
camel.go
@ -60,6 +60,9 @@ func toCamelInitCase(s string, initCase bool) string {
|
||||
|
||||
// ToCamel converts a string to CamelCase
|
||||
func ToCamel(s string) string {
|
||||
if uppercaseAcronym[s] {
|
||||
s = strings.ToLower(s)
|
||||
}
|
||||
return toCamelInitCase(s, true)
|
||||
}
|
||||
|
||||
@ -68,6 +71,9 @@ func ToLowerCamel(s string) string {
|
||||
if s == "" {
|
||||
return s
|
||||
}
|
||||
if uppercaseAcronym[s] {
|
||||
s = strings.ToLower(s)
|
||||
}
|
||||
if r := rune(s[0]); r >= 'A' && r <= 'Z' {
|
||||
s = strings.ToLower(string(r)) + s[1:]
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ func TestToCamel(t *testing.T) {
|
||||
{"AnyKind of_string", "AnyKindOfString"},
|
||||
{"odd-fix", "OddFix"},
|
||||
{"numbers2And55with000", "Numbers2And55With000"},
|
||||
{"ID", "Id"},
|
||||
}
|
||||
for _, i := range cases {
|
||||
in := i[0]
|
||||
@ -58,6 +59,7 @@ func TestToLowerCamel(t *testing.T) {
|
||||
{"", ""},
|
||||
{"AnyKind of_string", "anyKindOfString"},
|
||||
{"AnyKind.of-string", "anyKindOfString"},
|
||||
{"ID", "id"},
|
||||
}
|
||||
for _, i := range cases {
|
||||
in := i[0]
|
||||
|
Loading…
Reference in New Issue
Block a user