mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:40:54 +00:00
revert the snakeString
This commit is contained in:
parent
bb860d2752
commit
3f67c62dd8
@ -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",
|
||||
|
30
orm/utils.go
30
orm/utils.go
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user