Update snake.go

Consider userID to user_id
This commit is contained in:
bestplay 2018-04-27 15:32:37 +08:00 committed by GitHub
parent d192385340
commit d8275f2535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,12 +12,12 @@ func ToSnake(s string) string {
n := ""
for i, v := range s {
// treat acronyms as words, eg for JSONData -> JSON is a whole word
nextIsCapital := false
if i + 1 < len(s) {
w := s[i+1]
nextIsCapital = w >= 'A' && w <= 'Z'
preIsCapital := false
if i - 1 > 0 {
w := s[i-1]
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
n += "_" + string(v)
} else if v == ' ' {