Skip to content

Commit

Permalink
Merge pull request #4 from lilith44/develop
Browse files Browse the repository at this point in the history
fix: Underscore and Camel
  • Loading branch information
lilith44 authored Sep 7, 2023
2 parents bbfde66 + 00694c4 commit fa89b14
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions string.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ func Underscore(str string) string {
buf.Grow(len(str) + 1)
for i := range str {
if str[i] >= 'A' && str[i] <= 'Z' {
buf.WriteByte('_')
if i != 0 {
buf.WriteByte('_')
}
buf.WriteByte(str[i] - 'A' + 'a')
continue
}
Expand All @@ -49,7 +51,7 @@ func Camel(str string) string {
continue
}
b := str[i]
if toUpper {
if toUpper && b >= 'A' && b <= 'Z' {
b = b - 'a' + 'A'
}
buf.WriteByte(b)
Expand Down

0 comments on commit fa89b14

Please sign in to comment.