MCPcopy
hub / github.com/BishopFox/jsluice / GetNodeFunc

Method GetNodeFunc

objects.go:46–67  ·  view source on GitHub ↗

GetNodeFunc is a general-purpose method for finding object properties by their key. The provided function is called with each key in turn. The first time that function returns true the corresponding *Node for that key is returned.

(fn func(key string) bool)

Source from the content-addressed store, hash-verified

44// with each key in turn. The first time that function returns
45// true the corresponding *Node for that key is returned.
46func (o Object) GetNodeFunc(fn func(key string) bool) *Node {
47 if !o.HasValidNode() {
48 return &Node{}
49 }
50
51 count := int(o.node.NamedChildCount())
52
53 for i := 0; i < count; i++ {
54 pair := o.node.NamedChild(i)
55
56 if pair.Type() != "pair" {
57 continue
58 }
59
60 if !fn(pair.ChildByFieldName("key").RawString()) {
61 continue
62 }
63
64 return pair.ChildByFieldName("value")
65 }
66 return nil
67}
68
69// GetNode returns the matching *Node for a given key
70func (o Object) GetNode(key string) *Node {

Callers 2

GetNodeMethod · 0.95
GetNodeIMethod · 0.95

Calls 6

HasValidNodeMethod · 0.95
NamedChildCountMethod · 0.80
NamedChildMethod · 0.80
RawStringMethod · 0.80
ChildByFieldNameMethod · 0.80
TypeMethod · 0.45

Tested by

no test coverage detected