Skip to content

Commit

Permalink
strcase: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Oct 9, 2023
1 parent 2b333fc commit ddd0e39
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/strcase/strcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}

Expand All @@ -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()
Expand Down

0 comments on commit ddd0e39

Please sign in to comment.