Skip to content

Commit

Permalink
Fixing a bug found in tests for CamelCaseKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
Rican7 committed Jan 16, 2019
1 parent 46137a2 commit 13c2819
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ func CamelCaseKeys(lowerRepeatedCaps bool) Transformer {
if lowerRepeatedCaps {
// Remove repeated upper-case letters
key = repeatedUpperCaseWordBarrierRegex.ReplaceAllFunc(key, func(key []byte) []byte {
// If the last letter in the repeated-upper-case find is lower-case,
// then we have a successive "word"
if unicode.IsLower(rune(key[len(key)-1])) {
// Only lower-case the first "word"
return append(
key[0:1],
append(
bytes.ToLower(key[1:len(key)-2]),
key[len(key)-2:]...,
)...,
)
}

return append(key[0:1], bytes.ToLower(key[1:])...)
})
}
Expand Down

0 comments on commit 13c2819

Please sign in to comment.