Skip to content

Commit

Permalink
Simplify strcase
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed May 2, 2024
1 parent 91245ee commit ea8365b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/strcase/strcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"unicode"
)

var delimiters = map[rune]any{' ': struct{}{}, '_': struct{}{}, '-': struct{}{}, '.': struct{}{}}

// Delimited converts a string to delimited.lower.case, here using `.` as delimiter.
func Delimited(s string, d rune) string {
return convert(s, unicode.LowerCase, d)
Expand Down Expand Up @@ -44,8 +42,11 @@ func convert(s string, _case int, d rune) string {

for _, r := range s {
var isNumber bool
delimiter, isDelimiter := delimiters[r]
if !isDelimiter {

switch r {
case ' ', '_', '-', '.':
n.WriteRune(d)
default:
isNumber = unicode.IsNumber(r)
if wasNumber {
if !isNumber {
Expand All @@ -56,8 +57,6 @@ func convert(s string, _case int, d rune) string {
}

n.WriteRune(unicode.To(_case, r))
} else if delimiter != d {
n.WriteRune(d)
}

wasLower = unicode.IsLower(r)
Expand Down

0 comments on commit ea8365b

Please sign in to comment.