Skip to content

Commit

Permalink
Remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
stoewer committed Feb 26, 2020
1 parent 98db970 commit 6e37780
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions snake.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,6 @@ func UpperSnakeCase(s string) string {
return delimiterCase(s, '_', true)
}

// lowerDelimiterCase converts a string into snake_case or kebab-case depending on
// the delimiter passed in as second argument.
func lowerDelimiterCase(s string, delimiter rune) string {
s = strings.TrimSpace(s)
buffer := make([]rune, 0, len(s)+3)

var prev rune
var curr rune
for _, next := range s {
if isDelimiter(curr) {
if !isDelimiter(prev) {
buffer = append(buffer, delimiter)
}
} else if isUpper(curr) {
if isLower(prev) || (isUpper(prev) && isLower(next)) {
buffer = append(buffer, delimiter)
}
buffer = append(buffer, toLower(curr))
} else if curr != 0 {
buffer = append(buffer, curr)
}
prev = curr
curr = next
}

if len(s) > 0 {
if isUpper(curr) && isLower(prev) && prev != 0 {
buffer = append(buffer, delimiter)
}
buffer = append(buffer, toLower(curr))
}

return string(buffer)
}

// delimiterCase converts a string into snake_case or kebab-case depending on the delimiter passed
// as second argument. When upperCase is true the result will be UPPER_SNAKE_CASE or UPPER-KEBAB-CASE.
func delimiterCase(s string, delimiter rune, upperCase bool) string {
Expand Down

0 comments on commit 6e37780

Please sign in to comment.