diff --git a/pkg/strcase/strcase.go b/pkg/strcase/strcase.go index 6ecaa2e38..47647152c 100644 --- a/pkg/strcase/strcase.go +++ b/pkg/strcase/strcase.go @@ -29,13 +29,13 @@ func ScreamingSnake(s string) string { // convert converts a camelCase or space/underscore/hyphen/dot delimited string into various cases. // _case must be unicode.Lower or unicode.Upper. -// TODO: Treat acronyms as words and respect numbers. func convert(s string, _case int, d rune) string { if s == "" { return s } var wasLower bool + var wasNumber bool s = strings.TrimSpace(s) @@ -48,7 +48,11 @@ func convert(s string, _case int, d rune) string { if delimiter != d { n.WriteRune(d) } - } else if wasLower && unicode.IsUpper(r) { + } else if wasLower { + if unicode.IsUpper(r) { + n.WriteRune(d) + } + } else if wasNumber && !unicode.IsNumber(r) { n.WriteRune(d) } @@ -57,6 +61,9 @@ func convert(s string, _case int, d rune) string { } wasLower = unicode.IsLower(r) + if !wasLower { + wasNumber = unicode.IsNumber(r) + } } return n.String()