提交 5d2076c8 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

support ranges in [] like [a-z,0-9]:R

上级 1fa5a1a2
......@@ -24,6 +24,13 @@ fields:
postfix: "\t"
# width: 25
- field: test3
range: [a,b,c]
postfix: "\t"
- field: test4
range: [a-z,0-9]:R
- field: field_with_children
fields:
- field: child1
......
......@@ -114,72 +114,72 @@ fields:
prefix: "["
postfix: "]\t"
# - field: test20
# from: base.domain.domain.v1.yaml
# use: one_number_at_common
# prefix: ""
# postfix: "\t"
# - field: test21
# from: base.domain.domain.v1.yaml
# use: one_number_at_cn
# prefix: ""
# postfix: "\t"
# - field: test22
# from: base.domain.domain.v1.yaml
# use: one_number_at_new
# prefix: ""
# postfix: "\t"
#
# - field: test23
# from: base.domain.domain.v1.yaml
# use: one_letter_at_common
# prefix: ""
# postfix: "\t"
# - field: test24
# from: base.domain.domain.v1.yaml
# use: one_letter_at_cn
# prefix: ""
# postfix: "\t"
# - field: test25
# from: base.domain.domain.v1.yaml
# use: one_letter_at_new
# prefix: ""
# postfix: "\t"
#
# - field: test26
# from: base.domain.domain.v1.yaml
# use: numbers_at_common
# prefix: ""
# postfix: "\t"
# - field: test27
# from: base.domain.domain.v1.yaml
# use: numbers_at_cn
# prefix: ""
# postfix: "\t"
# - field: test28
# from: base.domain.domain.v1.yaml
# use: numbers_at_new
# prefix: ""
# postfix: "\t"
#
# - field: test29
# from: base.domain.domain.v1.yaml
# use: mixed_at_common
# prefix: ""
# postfix: "\t"
# - field: test30
# from: base.domain.domain.v1.yaml
# use: mixed_at_cn
# prefix: ""
# postfix: "\t"
# - field: test31
# from: base.domain.domain.v1.yaml
# use: mixed_at_new
# prefix: ""
# postfix: "\t"
#
# - field: test32
# from: base.domain.esp.v1.yaml
# use: esp
# prefix: ""
# postfix: "\t"
\ No newline at end of file
- field: test20
from: base.domain.domain.v1.yaml
use: one_number_at_common
prefix: ""
postfix: "\t"
- field: test21
from: base.domain.domain.v1.yaml
use: one_number_at_cn
prefix: ""
postfix: "\t"
- field: test22
from: base.domain.domain.v1.yaml
use: one_number_at_new
prefix: ""
postfix: "\t"
- field: test23
from: base.domain.domain.v1.yaml
use: one_letter_at_common
prefix: ""
postfix: "\t"
- field: test24
from: base.domain.domain.v1.yaml
use: one_letter_at_cn
prefix: ""
postfix: "\t"
- field: test25
from: base.domain.domain.v1.yaml
use: one_letter_at_new
prefix: ""
postfix: "\t"
- field: test26
from: base.domain.domain.v1.yaml
use: numbers_at_common
prefix: ""
postfix: "\t"
- field: test27
from: base.domain.domain.v1.yaml
use: numbers_at_cn
prefix: ""
postfix: "\t"
- field: test28
from: base.domain.domain.v1.yaml
use: numbers_at_new
prefix: ""
postfix: "\t"
- field: test29
from: base.domain.domain.v1.yaml
use: mixed_at_common
prefix: ""
postfix: "\t"
- field: test30
from: base.domain.domain.v1.yaml
use: mixed_at_cn
prefix: ""
postfix: "\t"
- field: test31
from: base.domain.domain.v1.yaml
use: mixed_at_new
prefix: ""
postfix: "\t"
- field: test32
from: base.domain.esp.v1.yaml
use: esp
prefix: ""
postfix: "\t"
\ No newline at end of file
......@@ -73,7 +73,7 @@ func GenerateFloatItemsByStep(start float64, end float64, step interface{}, repe
// return arr
//}
func getPrecision(base float64, step interface{}) int {
func GetPrecision(base float64, step interface{}) int {
val := base + step.(float64)
str1 := strconv.FormatFloat(base, 'f', -1, 64)
......@@ -87,4 +87,22 @@ func getPrecision(base float64, step interface{}) int {
} else {
return len(str2) - index2 - 1
}
}
func InterfaceToStr(val interface{}) string {
str := "n/a"
switch val.(type) {
case int64:
str = strconv.FormatInt(val.(int64), 10)
case float64:
precision := GetPrecision(val.(float64), 0)
str = strconv.FormatFloat(val.(float64), 'f', precision, 64)
case byte:
str = string(val.(byte))
case string:
str = val.(string)
default:
}
return str
}
\ No newline at end of file
......@@ -115,7 +115,7 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
rand = true
}
precision := getPrecision(float1, step)
precision := GetPrecision(float1, step)
if (float1 > float2 && step.(float64) > 0) || (float1 < float2 && step.(float64) < 0) {
step = -1 * step.(float64)
......@@ -147,6 +147,9 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string, repeat int) (items []interface{}) {
elemArr := ParseDesc(desc)
step, _ := strconv.Atoi(stepStr)
if step == 0 {
step = 1
}
total := 0
if field.Path != "" && stepStr == "r" {
......
......@@ -2,6 +2,7 @@ package gen
import (
"fmt"
"github.com/easysoft/zendata/src/model"
"github.com/easysoft/zendata/src/utils/const"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"regexp"
......@@ -121,11 +122,37 @@ 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) {
desc = removeBoundary(desc)
arr := strings.Split(desc, ",")
temp := ""
for _, item := range arr {
if isBoundaryStr(item) {
tempField := model.DefField{}
values := CreateValuesFromInterval(&tempField, item, "1", 1)
for _, val := range values {
temp += InterfaceToStr(val) + ","
}
} else {
temp += item + ","
}
}
temp = strings.TrimSuffix(temp, ",")
desc = string(constant.LeftBrackets) + temp + string(constant.RightBrackets)
typ = "literal"
return
}
if strings.Contains(desc, ",") || strings.Contains(desc, "`") || !strings.Contains(desc, "-") {
typ = "literal"
} else {
temp := strings.ReplaceAll(desc, string(constant.LeftBrackets), "")
temp = strings.ReplaceAll(temp,string(constant.RightBrackets), "")
temp := removeBoundary(desc)
if isBoundaryStr(temp) {
typ = "interval"
......@@ -138,8 +165,19 @@ func ParseRangeSectionDesc(str string) (typ string, desc string) {
return
}
func removeBoundary(str string) string {
str = strings.TrimLeft(str, string(constant.LeftBrackets))
str = strings.TrimRight(str, string(constant.RightBrackets))
return str
}
func isBoundaryStr(str string) bool {
arr := strings.Split(str, "-")
if len(arr) < 2 {
return false
}
left := strings.TrimSpace(arr[0])
right := strings.TrimSpace(arr[1])
......
......@@ -5,166 +5,166 @@ version: 1.0
field: domain
instances:
- instance: one_number_at_common
note: 单数字域名
fields:
- field: part1
range: 1-9
rand: true
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: all
- instance: one_number_at_cn
note: 单数字CN域名
prefix:
fields:
- field: part1
range: 1-9
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: cn
- instance: one_number_at_new
note: 单数字新域名
prefix:
fields:
- field: part1
range: 1-9
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: new
- instance: one_letter_at_common
note: 单字母域名
prefix:
fields:
- field: part1
range: a-z
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: all
- instance: one_letter_at_cn
note: 单字母CN域名
prefix:
fields:
- field: part1
range: a-z
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: cn
- instance: one_letter_at_new
note: 单字母新域名
prefix:
fields:
- field: part1
range: a-z
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: new
- instance: numbers_at_common
note: 纯数字域名
prefix:
fields:
- field: part1
range: 0-9
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: all
- instance: numbers_at_cn
note: 纯数字CN域名
prefix:
fields:
- field: part1
range: 0-9
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: cn
- instance: numbers_at_new
note: 纯数字新域名
prefix:
fields:
- field: part1
range: a-z
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: new
- instance: letters_at_common
note: 纯字母域名
prefix:
fields:
- field: part1
range: a-z
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: all
- instance: letters_at_cn
note: 纯字母CN域名
prefix:
fields:
- field: part1
range: a-z
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: cn
- instance: letters_at_new
note: 纯字母新域名
prefix:
fields:
- field: part1
range: a-z
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: new
# - instance: one_number_at_common
# note: 单数字域名
# fields:
# - field: part1
# range: 1-9
# rand: true
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: all
# - instance: one_number_at_cn
# note: 单数字CN域名
# prefix:
# fields:
# - field: part1
# range: 1-9
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: cn
# - instance: one_number_at_new
# note: 单数字新域名
# prefix:
# fields:
# - field: part1
# range: 1-9
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: new
#
# - instance: one_letter_at_common
# note: 单字母域名
# prefix:
# fields:
# - field: part1
# range: a-z
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: all
# - instance: one_letter_at_cn
# note: 单字母CN域名
# prefix:
# fields:
# - field: part1
# range: a-z
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: cn
# - instance: one_letter_at_new
# note: 单字母新域名
# prefix:
# fields:
# - field: part1
# range: a-z
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: new
#
# - instance: numbers_at_common
# note: 纯数字域名
# prefix:
# fields:
# - field: part1
# range: 0-9
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: all
# - instance: numbers_at_cn
# note: 纯数字CN域名
# prefix:
# fields:
# - field: part1
# range: 0-9
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: cn
# - instance: numbers_at_new
# note: 纯数字新域名
# prefix:
# fields:
# - field: part1
# range: a-z
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: new
#
# - instance: letters_at_common
# note: 纯字母域名
# prefix:
# fields:
# - field: part1
# range: a-z
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: all
# - instance: letters_at_cn
# note: 纯字母CN域名
# prefix:
# fields:
# - field: part1
# range: a-z
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: cn
# - instance: letters_at_new
# note: 纯字母新域名
# prefix:
# fields:
# - field: part1
# range: a-z
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: new
- instance: mixed_at_common
note: 字母和数字域名
prefix:
fields:
- field: part1
range: a-z,0-9
range: [a-z,0-9]:R
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: all
- instance: mixed_at_cn
note: 字母和数字CN域名
prefix:
fields:
- field: part1
range: a-z,0-9
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: cn
- instance: mixed_at_new
note: 字母和数字新域名
prefix:
fields:
- field: part1
range: a-z,0-9
loop: 5-8
postfix: "."
- field: part2
from: base.domain.postfix.v1.yaml
use: new
\ No newline at end of file
# - instance: mixed_at_cn
# note: 字母和数字CN域名
# prefix:
# fields:
# - field: part1
# range: a-z,0-9
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: cn
# - instance: mixed_at_new
# note: 字母和数字新域名
# prefix:
# fields:
# - field: part1
# range: a-z,0-9
# loop: 5-8
# postfix: "."
# - field: part2
# from: base.domain.postfix.v1.yaml
# use: new
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册