Update snake.go
Consider userID to user_id
This commit is contained in:
parent
d192385340
commit
d8275f2535
10
snake.go
10
snake.go
@ -12,12 +12,12 @@ func ToSnake(s string) string {
|
|||||||
n := ""
|
n := ""
|
||||||
for i, v := range s {
|
for i, v := range s {
|
||||||
// treat acronyms as words, eg for JSONData -> JSON is a whole word
|
// treat acronyms as words, eg for JSONData -> JSON is a whole word
|
||||||
nextIsCapital := false
|
preIsCapital := false
|
||||||
if i + 1 < len(s) {
|
if i - 1 > 0 {
|
||||||
w := s[i+1]
|
w := s[i-1]
|
||||||
nextIsCapital = w >= 'A' && w <= 'Z'
|
preIsCapital = w >= 'A' && w <= 'Z'
|
||||||
}
|
}
|
||||||
if i > 0 && v >= 'A' && v <= 'Z' && n[len(n)-1] != '_' && !nextIsCapital {
|
if i > 0 && v >= 'A' && v <= 'Z' && n[len(n)-1] != '_' && !preIsCapital {
|
||||||
// add underscore if next letter is a capital
|
// add underscore if next letter is a capital
|
||||||
n += "_" + string(v)
|
n += "_" + string(v)
|
||||||
} else if v == ' ' {
|
} else if v == ' ' {
|
||||||
|
Loading…
Reference in New Issue
Block a user