提交 5786ed8a 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

refer to other yaml file's data

上级 20940883
......@@ -38,6 +38,11 @@ fields:
- from: custom.test.number.v1.yaml
use: large{3}
- field: field_use_yaml
range: test.yaml{2},1-9
postfix: "\t"
- field: field_literal
range: "`0000-00`,`AA[2,a-z]`,[1-3]:2{3},`[1-3]:2{3}`"
type: text
\ No newline at end of file
type: text
......@@ -39,19 +39,19 @@ func CreateFieldValues(field *model.DefField, fieldValue *model.FieldWithValues)
func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWithValues) {
rang := field.Range
rangeItems := ParseRange(rang) // 1
rangeSections := ParseRangeProperty(rang) // 1
index := 0
for _, rangeItem := range rangeItems {
for _, rangeSection := range rangeSections {
if index >= constant.MaxNumb { break }
if rangeItem == "" { continue }
if rangeSection == "" { continue }
descStr, stepStr, repeat := ParseRangeItem(rangeItem) // 2
descStr, stepStr, repeat := ParseRangeSection(rangeSection) // 2
if strings.ToLower(stepStr) == "r" {
(*field).IsRand = true
}
typ, desc := ParseEntry(descStr) // 3
typ, desc := ParseRangeSectionDesc(descStr) // 3
items := make([]interface{}, 0)
if typ == "literal" {
......
......@@ -3,18 +3,14 @@ package gen
import (
"fmt"
"github.com/easysoft/zendata/src/utils/const"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"regexp"
"strconv"
"strings"
"unicode"
)
/**
split field range string with comma to a array, ignore the comma in []
1-2:R,[user1,user2]{2} -> 1-2:R
[user1,user2]{2}
*/
func ParseRange(rang string) []string {
func ParseRangeProperty(rang string) []string {
items := make([]string, 0)
bracketsOpen := false
......@@ -79,7 +75,7 @@ func ParseDesc(desc string) (items []string) {
step =>1
repeat =>2
*/
func ParseRangeItem(item string) (entry string, step string, repeat int) {
func ParseRangeSection(item string) (entry string, step string, repeat int) {
item = strings.TrimSpace(item)
runeArr := []rune(item)
if (runeArr[0] == constant.Backtick && runeArr[len(runeArr) - 1] == constant.Backtick) || // `xxx`
......@@ -117,9 +113,14 @@ func ParseRangeItem(item string) (entry string, step string, repeat int) {
[user1,user2] -> type => literal
desc => user2,user3
*/
func ParseEntry(str string) (typ string, desc string) {
func ParseRangeSectionDesc(str string) (typ string, desc string) {
desc = strings.TrimSpace(str)
if stringUtils.EndWith(desc, ".yaml") { // refer to another yaml file
typ = "yaml"
return
}
if strings.Contains(desc, ",") || strings.Contains(desc, "`") || !strings.Contains(desc, "-") {
typ = "literal"
} else {
......
......@@ -130,6 +130,13 @@ func AddPad(str string, field model.DefField) string {
return str
}
func StartWith(str, sub string) bool {
return strings.Index(str, sub) == 0
}
func EndWith(str, sub string) bool {
return strings.LastIndex(str, sub) == len(str) -len(sub)
}
func ConvertForSql(str string) (ret string) {
arr := []rune(str)
......
无法预览此类型文件
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册