Commit 3f67c62d authored by astaxie's avatar astaxie

revert the snakeString

parent bb860d27
......@@ -2135,13 +2135,13 @@ func TestSnake(t *testing.T) {
"i": "i",
"I": "i",
"iD": "i_d",
"ID": "id",
"NO": "no",
"NOO": "noo",
"NOOooOOoo": "noo_oo_oo_oo",
"OrderNO": "order_no",
"ID": "i_d",
"NO": "n_o",
"NOO": "n_o_o",
"NOOooOOoo": "n_o_ooo_o_ooo",
"OrderNO": "order_n_o",
"tagName": "tag_name",
"tag_Name": "tag_name",
"tag_Name": "tag__name",
"tag_name": "tag_name",
"_tag_name": "_tag_name",
"tag_666name": "tag_666name",
......
......@@ -184,33 +184,15 @@ func ToInt64(value interface{}) (d int64) {
// snake string, XxYy to xx_yy , XxYY to xx_yy
func snakeString(s string) string {
data := make([]byte, 0, len(s)*2)
j := false
num := len(s)
for i := 0; i < num; i++ {
d := s[i]
if i > 0 && d != '_' && s[i-1] != '_' {
need := false
// upper as 1, lower as 0
// XX -> 11 -> 11
// Xx -> 10 -> 10
// XxYyZZ -> 101011 -> 10_10_11
isUpper := d >= 'A' && d <= 'Z'
preIsUpper := s[i-1] >= 'A' && s[i-1] <= 'Z'
if isUpper {
// like : xxYy
if !preIsUpper {
need = true
}
} else {
if preIsUpper {
// ignore "Xy" in "xxXyy"
if i-2 >= 0 && s[i-2] >= 'A' && s[i-2] <= 'Z' {
need = true
}
}
}
if need {
data = append(data, '_')
}
if i > 0 && d >= 'A' && d <= 'Z' && j {
data = append(data, '_')
}
if d != '_' {
j = true
}
data = append(data, d)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment