Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
3f67c62d
Commit
3f67c62d
authored
Aug 29, 2016
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert the snakeString
parent
bb860d27
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
30 deletions
+12
-30
orm_test.go
orm/orm_test.go
+6
-6
utils.go
orm/utils.go
+6
-24
No files found.
orm/orm_test.go
View file @
3f67c62d
...
...
@@ -2135,13 +2135,13 @@ func TestSnake(t *testing.T) {
"i"
:
"i"
,
"I"
:
"i"
,
"iD"
:
"i_d"
,
"ID"
:
"id"
,
"NO"
:
"no"
,
"NOO"
:
"n
o
o"
,
"NOOooOOoo"
:
"n
oo_oo_oo_
oo"
,
"OrderNO"
:
"order_no"
,
"ID"
:
"i
_
d"
,
"NO"
:
"n
_
o"
,
"NOO"
:
"n
_o_
o"
,
"NOOooOOoo"
:
"n
_o_ooo_o_o
oo"
,
"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"
,
...
...
orm/utils.go
View file @
3f67c62d
...
...
@@ -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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment