This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
def.go
94 lines (79 loc) · 1.67 KB
/
def.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
90
91
92
93
94
package schemax
/*
defmap.go defines map related methods to allow simple interaction
with instances of types that have been marshaled into map form.
*/
func (r DefinitionMaps) Len() int {
return len(r)
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r DefinitionMaps) IsZero() bool {
return r.Len() == 0
}
func (r DefinitionMaps) Index(idx int) DefinitionMap {
if r.Len() < idx {
return DefinitionMap{}
}
return r[idx]
}
func (r DefinitionMap) Get(id string) (val []string) {
var key string
for key, val = range r {
if eq(key, id) {
break
}
}
return
}
func (r DefinitionMap) Contains(id string) bool {
return len(r.Get(id)) > 0
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r DefinitionMap) IsZero() bool {
return r.Len() == 0
}
func (r DefinitionMap) Len() int {
return len(r)
}
/*
Keys returns slices of names, each representing a key residing within
the receiver instance. Note that the order of keys cannot be guaranteed.
*/
func (r DefinitionMap) Keys() (keys []string) {
for key := range r {
keys = append(keys, key)
}
return
}
/*
clean removes valueless (or zero-length valued) keys/value pairs
from the receiver instance.
*/
func (r *DefinitionMap) clean() {
for k, v := range *r {
if len(v) == 0 {
delete(*r, k)
} else if len(v[0]) == 0 {
delete(*r, k)
} else if k == `MUB` && v[0] == `0` {
delete(*r, k)
}
}
}
/*
Type returns the first value assigned to the TYPE key, if defined,
else `unknown` is returned.
*/
func (r DefinitionMap) Type() (t string) {
t = `unknown`
if _type := r.Get(`TYPE`); len(_type) > 0 {
if _t := _type[0]; len(_t) > 0 {
t = _t
}
}
return
}