Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
11a96df7
Z
zendata
项目概览
易企天创
/
zendata
10 个月 前同步成功
通知
17
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
11a96df7
编写于
12月 07, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
close task#8565
上级
a6f1db43
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
25 deletion
+42
-25
demo/test.yaml
demo/test.yaml
+6
-1
src/gen/list.go
src/gen/list.go
+17
-9
src/gen/parser.go
src/gen/parser.go
+19
-15
未找到文件。
demo/test.yaml
浏览文件 @
11a96df7
...
...
@@ -24,4 +24,9 @@ fields:
-
field
:
field_with_children
prefix
:
"
{"
postfix
:
"
}
\t
"
\ No newline at end of file
postfix
:
"
}
\t
"
-
field
:
chinese
range
:
[
`
测试`
,
实测
]
prefix
:
"
{"
postfix
:
"
}
\t
"
src/gen/list.go
浏览文件 @
11a96df7
...
...
@@ -39,19 +39,23 @@ func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWit
return
}
rangeSections
:=
ParseRangeProperty
(
rang
)
// 1
rangeSections
:=
ParseRangeProperty
(
rang
)
//
parse
1
index
:=
0
for
_
,
rangeSection
:=
range
rangeSections
{
if
index
>=
constant
.
MaxNumb
{
break
}
if
rangeSection
==
""
{
continue
}
if
index
>=
constant
.
MaxNumb
{
break
}
if
rangeSection
==
""
{
continue
}
descStr
,
stepStr
,
repeat
:=
ParseRangeSection
(
rangeSection
)
// 2
descStr
,
stepStr
,
repeat
:=
ParseRangeSection
(
rangeSection
)
//
parse
2
if
strings
.
ToLower
(
stepStr
)
==
"r"
{
(
*
field
)
.
IsRand
=
true
}
typ
,
desc
:=
ParseRangeSectionDesc
(
descStr
)
// 3
typ
,
desc
:=
ParseRangeSectionDesc
(
descStr
)
//
parse
3
items
:=
make
([]
interface
{},
0
)
if
typ
==
"literal"
{
...
...
@@ -145,8 +149,8 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
rand
=
true
}
if
(
strings
.
Compare
(
startStr
,
endStr
)
>
0
&&
step
.
(
int
)
>
0
)
||
(
strings
.
Compare
(
startStr
,
endStr
)
<
0
&&
step
.
(
int
)
<
0
)
{
if
(
strings
.
Compare
(
startStr
,
endStr
)
>
0
&&
step
.
(
int
)
>
0
)
||
(
strings
.
Compare
(
startStr
,
endStr
)
<
0
&&
step
.
(
int
)
<
0
)
{
step
=
-
1
*
step
.
(
int
)
}
return
"char"
,
step
,
0
,
rand
...
...
@@ -206,7 +210,9 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
elemArr
:=
strings
.
Split
(
desc
,
"-"
)
startStr
:=
elemArr
[
0
]
endStr
:=
startStr
if
len
(
elemArr
)
>
1
{
endStr
=
elemArr
[
1
]
}
if
len
(
elemArr
)
>
1
{
endStr
=
elemArr
[
1
]
}
dataType
,
step
,
precision
,
rand
:=
CheckRangeType
(
startStr
,
endStr
,
stepStr
)
...
...
@@ -236,7 +242,9 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
items
=
GenerateByteItems
(
startStr
[
0
],
endStr
[
0
],
step
.
(
int
),
rand
,
repeat
)
}
else
if
dataType
==
"string"
{
if
repeat
==
0
{
repeat
=
1
}
if
repeat
==
0
{
repeat
=
1
}
for
i
:=
0
;
i
<
repeat
;
i
++
{
items
=
append
(
items
,
desc
)
}
...
...
src/gen/parser.go
浏览文件 @
11a96df7
...
...
@@ -34,7 +34,7 @@ func ParseRangeProperty(rang string) []string {
backtickOpen
=
false
}
if
i
==
len
(
runeArr
)
-
1
{
if
i
==
len
(
runeArr
)
-
1
{
temp
+=
fmt
.
Sprintf
(
"%c"
,
c
)
items
=
append
(
items
,
temp
)
}
else
if
!
bracketsOpen
&&
!
backtickOpen
&&
c
==
','
{
...
...
@@ -62,12 +62,12 @@ func ParseDesc(desc string) (items []string) {
runeArr
:=
[]
rune
(
desc
)
if
runeArr
[
0
]
==
constant
.
Backtick
&&
runeArr
[
len
(
runeArr
)
-
1
]
==
constant
.
Backtick
{
// `xxx`
desc
=
string
(
runeArr
[
1
:
len
(
desc
)
-
1
])
if
runeArr
[
0
]
==
constant
.
Backtick
&&
runeArr
[
len
(
runeArr
)
-
1
]
==
constant
.
Backtick
{
// `xxx`
desc
=
string
(
runeArr
[
1
:
len
(
runeArr
)
-
1
])
items
=
append
(
items
,
desc
)
}
else
if
runeArr
[
0
]
==
constant
.
LeftBrackets
&&
runeArr
[
len
(
runeArr
)
-
1
]
==
constant
.
RightBrackets
{
// [abc,123]
desc
=
string
(
runeArr
[
1
:
len
(
desc
)
-
1
])
}
else
if
runeArr
[
0
]
==
constant
.
LeftBrackets
&&
runeArr
[
len
(
runeArr
)
-
1
]
==
constant
.
RightBrackets
{
// [abc,123]
desc
=
string
(
runeArr
[
1
:
len
(
runeArr
)
-
1
])
items
=
strings
.
Split
(
desc
,
","
)
}
else
{
...
...
@@ -92,12 +92,14 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
}
runeArr
:=
[]
rune
(
item
)
if
(
runeArr
[
0
]
==
constant
.
Backtick
&&
runeArr
[
len
(
runeArr
)
-
1
]
==
constant
.
Backtick
)
||
// `xxx`
(
string
(
item
[
0
])
==
string
(
constant
.
LeftBrackets
)
&&
// (xxx)
string
(
item
[
len
(
item
)
-
1
])
==
string
(
constant
.
RightBrackets
))
{
if
(
runeArr
[
0
]
==
constant
.
Backtick
&&
runeArr
[
len
(
runeArr
)
-
1
]
==
constant
.
Backtick
)
||
// `xxx`
(
string
(
runeArr
[
0
])
==
string
(
constant
.
LeftBrackets
)
&&
// (xxx)
string
(
runeArr
[
len
(
runeArr
)
-
1
])
==
string
(
constant
.
RightBrackets
))
{
entry
=
item
if
repeat
==
0
{
repeat
=
1
}
if
repeat
==
0
{
repeat
=
1
}
return
}
...
...
@@ -114,7 +116,9 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
step
=
strings
.
ToLower
(
sectionArr
[
1
])
}
if
repeat
==
0
{
repeat
=
1
}
if
repeat
==
0
{
repeat
=
1
}
return
entry
,
step
,
repeat
}
...
...
@@ -127,6 +131,7 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
*/
func
ParseRangeSectionDesc
(
str
string
)
(
typ
string
,
desc
string
)
{
desc
=
strings
.
TrimSpace
(
str
)
runeArr
:=
[]
rune
(
desc
)
if
desc
==
""
{
typ
=
"literal"
...
...
@@ -138,8 +143,8 @@ func ParseRangeSectionDesc(str string) (typ string, desc string) {
return
}
if
string
(
desc
[
0
])
==
string
(
constant
.
LeftBrackets
)
&&
// [a-z,1-9,userA,UserB]
string
(
desc
[
len
(
desc
)
-
1
])
==
string
(
constant
.
RightBrackets
)
{
if
string
(
runeArr
[
0
])
==
string
(
constant
.
LeftBrackets
)
&&
// [a-z,1-9,userA,UserB]
string
(
runeArr
[
len
(
runeArr
)
-
1
])
==
string
(
constant
.
RightBrackets
)
{
desc
=
removeBoundary
(
desc
)
arr
:=
strings
.
Split
(
desc
,
","
)
...
...
@@ -167,7 +172,7 @@ func ParseRangeSectionDesc(str string) (typ string, desc string) {
if
strings
.
Contains
(
desc
,
","
)
||
strings
.
Contains
(
desc
,
"`"
)
||
!
strings
.
Contains
(
desc
,
"-"
)
{
typ
=
"literal"
}
else
{
}
else
{
temp
:=
removeBoundary
(
desc
)
if
isScopeStr
(
temp
)
{
...
...
@@ -197,7 +202,7 @@ func isScopeStr(str string) bool {
left
:=
strings
.
TrimSpace
(
arr
[
0
])
right
:=
strings
.
TrimSpace
(
arr
[
1
])
if
len
(
left
)
!=
1
||
len
(
right
)
!=
1
{
if
len
(
left
)
!=
1
||
len
(
right
)
!=
1
{
// more than on char, must be number
leftRune
:=
[]
rune
(
string
(
left
[
0
]))[
0
]
rightRune
:=
[]
rune
(
string
(
right
[
0
]))[
0
]
...
...
@@ -234,4 +239,3 @@ func isCharOrNumberScope(str string) bool {
return
false
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录