forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataproc.go
89 lines (60 loc) · 1.85 KB
/
dataproc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package v2
import (
"strings"
"github.com/davyxu/tabtoy/v2/filter"
"github.com/davyxu/tabtoy/v2/i18n"
"github.com/davyxu/tabtoy/v2/model"
)
func coloumnProcessor(file model.GlobalChecker, record *model.Record, fd *model.FieldDescriptor, raw string, sugguestIgnore bool) bool {
spliter := fd.ListSpliter()
if fd.IsRepeated && spliter != "" {
valueList := strings.Split(raw, spliter)
var node *model.Node
if fd.Type != model.FieldType_Struct {
node = record.NewNodeByDefine(fd)
}
for _, v := range valueList {
rawSingle := strings.TrimSpace(v)
// 结构体要多添加一个节点, 处理repeated 结构体情况
if fd.Type == model.FieldType_Struct {
node = record.NewNodeByDefine(fd)
node.StructRoot = true
node = node.AddKey(fd)
}
if raw != "" {
if !dataProcessor(file, fd, rawSingle, node) {
return false
}
}
}
} else { // 普通数据/repeated单元格分多个列
node := record.NewNodeByDefine(fd)
node.SugguestIgnore = sugguestIgnore
// 结构体要多添加一个节点, 处理repeated 结构体情况
if fd.Type == model.FieldType_Struct {
node.StructRoot = true
node = node.AddKey(fd)
}
node.SugguestIgnore = sugguestIgnore
if !dataProcessor(file, fd, raw, node) {
return false
}
}
return true
}
func dataProcessor(gc model.GlobalChecker, fd *model.FieldDescriptor, raw string, node *model.Node) bool {
// 单值
if cv, ok := filter.ConvertValue(fd, raw, gc.GlobalFileDesc(), node); !ok {
goto ConvertError
} else {
// 值重复检查
if fd.Meta.GetBool("RepeatCheck") && !gc.CheckValueRepeat(fd, cv) {
log.Errorf("%s, %s raw: '%s'", i18n.String(i18n.DataSheet_ValueRepeated), fd.String(), cv)
return false
}
}
return true
ConvertError:
log.Errorf("%s, %s raw: '%s'", i18n.String(i18n.DataSheet_ValueConvertError), fd.String(), raw)
return false
}