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
99093693
Commit
99093693
authored
Dec 26, 2016
by
astaxie
Committed by
GitHub
Dec 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2346 from legendtkl/master
Modify func camelString() to be more robust
parents
fa12dcf7
c9c284be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
13 deletions
+44
-13
utils.go
orm/utils.go
+8
-13
utils_test.go
orm/utils_test.go
+36
-0
No files found.
orm/utils.go
View file @
99093693
...
...
@@ -219,22 +219,17 @@ func snakeString(s string) string {
// camel string, xx_yy to XxYy
func
camelString
(
s
string
)
string
{
data
:=
make
([]
byte
,
0
,
len
(
s
))
j
:=
false
k
:=
false
num
:=
len
(
s
)
-
1
flag
,
num
:=
true
,
len
(
s
)
-
1
for
i
:=
0
;
i
<=
num
;
i
++
{
d
:=
s
[
i
]
if
k
==
false
&&
d
>=
'A'
&&
d
<=
'Z'
{
k
=
true
}
if
d
>=
'a'
&&
d
<=
'z'
&&
(
j
||
k
==
false
)
{
d
=
d
-
32
j
=
false
k
=
true
}
if
k
&&
d
==
'_'
&&
num
>
i
&&
s
[
i
+
1
]
>=
'a'
&&
s
[
i
+
1
]
<=
'z'
{
j
=
true
if
d
==
'_'
{
flag
=
true
continue
}
else
if
flag
==
true
{
if
d
>=
'a'
&&
d
<=
'z'
{
d
=
d
-
32
}
flag
=
false
}
data
=
append
(
data
,
d
)
}
...
...
orm/utils_test.go
0 → 100644
View file @
99093693
// Copyright 2014 beego Author. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
orm
import
(
"testing"
)
func
TestCamelString
(
t
*
testing
.
T
)
{
snake
:=
[]
string
{
"pic_url"
,
"hello_world_"
,
"hello__World"
,
"_HelLO_Word"
,
"pic_url_1"
,
"pic_url__1"
}
camel
:=
[]
string
{
"PicUrl"
,
"HelloWorld"
,
"HelloWorld"
,
"HelLOWord"
,
"PicUrl1"
,
"PicUrl1"
}
answer
:=
make
(
map
[
string
]
string
)
for
i
,
v
:=
range
snake
{
answer
[
v
]
=
camel
[
i
]
}
for
_
,
v
:=
range
snake
{
res
:=
camelString
(
v
)
if
res
!=
answer
[
v
]
{
t
.
Error
(
"Unit Test Fail:"
,
v
,
res
,
answer
[
v
])
}
}
}
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