forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metainfo.go
58 lines (43 loc) · 838 Bytes
/
metainfo.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
package model
import (
"sort"
"github.com/davyxu/golexer"
)
var builtinTag = map[string]bool{
"MakeIndex": true,
"Alias": true,
"Default": true,
"ListSpliter": true,
"RepeatCheck": true,
"TableName": true,
"Package": true,
"OutputTag": true,
}
func IsSystemTag(tag string) bool {
_, ok := builtinTag[tag]
return ok
}
type MetaInfo struct {
*golexer.KVPair
}
func (self *MetaInfo) VisitUserMeta(callback func(string, interface{}) bool) {
sortedKeys := make([]string, 0)
for k, _ := range self.Raw() {
if IsSystemTag(k) {
continue
}
sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys)
for _, k := range sortedKeys {
v, _ := self.Raw()[k]
if !callback(k, v) {
return
}
}
}
func NewMetaInfo() *MetaInfo {
return &MetaInfo{
KVPair: golexer.NewKVPair(),
}
}