Skip to content

Commit

Permalink
Capitalize complete acronym if it is first segment
Browse files Browse the repository at this point in the history
in pascalized ident

Fixes #39
  • Loading branch information
breml authored and sio4 committed Mar 12, 2022
1 parent 944b32d commit e28b95b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions camelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func Test_Camelize(t *testing.T) {
{"statuses", "statuses"},
{"People", "people"},
{"people", "people"},
{"ip_address", "ipAddress"},
{"some_url", "someURL"},
}

for _, tt := range table {
Expand Down
11 changes: 9 additions & 2 deletions pascalize.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package flect

import (
"unicode"
"strings"
)

// Pascalize returns a string with each segment capitalized
Expand All @@ -21,5 +21,12 @@ func (i Ident) Pascalize() Ident {
if len(c.String()) == 0 {
return c
}
return New(string(unicode.ToUpper(rune(c.Original[0]))) + c.Original[1:])
if len(i.Parts) == 0 {
return i
}
capLen := 1
if _, ok := baseAcronyms[strings.ToUpper(i.Parts[0])]; ok {
capLen = len(i.Parts[0])
}
return New(string(strings.ToUpper(c.Original[0:capLen])) + c.Original[capLen:])
}
2 changes: 2 additions & 0 deletions pascalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func Test_Pascalize(t *testing.T) {
{"i've read a book! have you?", "IveReadABookHaveYou"},
{"This is `code` ok", "ThisIsCodeOK"},
{"id", "ID"},
{"ip_address", "IPAddress"},
{"some_url", "SomeURL"},
}

for _, tt := range table {
Expand Down

0 comments on commit e28b95b

Please sign in to comment.