forked from JesseCoretta/go-schemax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macros.go
75 lines (62 loc) · 1.28 KB
/
macros.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
package schemax
func newMacros() Macros {
return Macros{
make(macros, 0),
}
}
/*
Resolve returns string y (a name) following an attempt to forward-resolve
string x (numeric OID). The Boolean value (found) is returned indicative
of a successful resolution attempt.
Case is not significant in the matching process.
*/
func (r Macros) Resolve(x string) (y string, found bool) {
if r.macros == nil {
return
}
for k, v := range r.macros {
if eq(x, k) {
y = v
found = true
break
}
}
return
}
/*
ReverseResolve returns string x (a numeric OID) following an attempt to
reverse-resolve string y (name). The Boolean value (found) is returned
indicative of a successful resolution attempt.
Case is not significant in the matching process.
*/
func (r Macros) ReverseResolve(y string) (x string, found bool) {
if r.macros == nil {
return
}
for k, v := range r.macros {
if eq(y, v) {
x = k
found = true
break
}
}
return
}
/*
Set assigns value y (macro name) to key x (numeric OID).
This is a fluent method.
*/
func (r Macros) Set(x, y string) Macros {
r.macros[x] = y
return r
}
/*
Keys returns all numeric OID keys present within the receiver instance.
*/
func (r Macros) Keys() []string {
var s []string
for k := range r.macros {
s = append(s, k)
}
return s
}