Skip to content

Commit

Permalink
Fix unnecessary function call ReplaceAcronymRunes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaksv committed Sep 20, 2023
1 parent 4a04f33 commit cad9ffd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions strcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ func ParseRunes(rs []rune) [][]rune {
func camelCase(runes []rune, upper bool, replaceAcronym bool) []rune {
camelCase := make([]rune, 0, len(runes))
for i, rs := range ParseRunes(runes) {
if nRs, ok := ReplaceAcronymRunes(rs); replaceAcronym && ok {
var nRs []rune
var foundReplace bool
if replaceAcronym {
nRs, foundReplace = ReplaceAcronymRunes(rs)
}

if foundReplace {
rs = nRs
} else if i == 0 {
if upper {
Expand Down Expand Up @@ -267,12 +273,16 @@ func ReplaceAcronymsRunes(runeWords [][]rune) [][]rune {
}

func ReplaceAcronymRunes(runeWord []rune) ([]rune, bool) {
return replaceAcronymRunes(runeWord, false)
}

func replaceAcronymRunes(runeWord []rune, exit bool) ([]rune, bool) {
if acr, ok := acrMap.Load(string(runeWord)); ok {
if acr, ok := acr.([]rune); ok {
return acr, true
}
} else if !isLower(runeWord) {
return ReplaceAcronymRunes(toLowerRunes(runeWord))
} else if !exit {
return replaceAcronymRunes(toLowerRunes(runeWord), true)
}
return runeWord, false
}
Expand Down

0 comments on commit cad9ffd

Please sign in to comment.