From d8275f25354ae28ae89eb2c2b1d33cdae78609c5 Mon Sep 17 00:00:00 2001 From: bestplay <476128561@qq.com> Date: Fri, 27 Apr 2018 15:32:37 +0800 Subject: [PATCH] Update snake.go Consider userID to user_id --- snake.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/snake.go b/snake.go index 1af946b..d73cab1 100644 --- a/snake.go +++ b/snake.go @@ -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 == ' ' {