MCPcopy Index your code
hub / github.com/VirusTotal/vt-cli / filterMap

Function filterMap

utils/filter.go:83–138  ·  view source on GitHub ↗

filterMap is the internal version of FilterMap.

(m reflect.Value, include, exclude []glob.Glob, prefix string)

Source from the content-addressed store, hash-verified

81
82// filterMap is the internal version of FilterMap.
83func filterMap(m reflect.Value, include, exclude []glob.Glob, prefix string) reflect.Value {
84
85 result := reflect.MakeMap(m.Type())
86
87 for _, k := range m.MapKeys() {
88 path := k.String()
89 if prefix != "" {
90 path = prefix + "." + path
91 }
92 match := false
93 for _, p := range include {
94 if p.Match(path) {
95 match = true
96 break
97 }
98 }
99 for _, p := range exclude {
100 if p.Match(path) {
101 match = false
102 break
103 }
104 }
105
106 v := actualValue(m.MapIndex(k))
107
108 switch v.Kind() {
109 case reflect.Map:
110 fm := filterMap(v, include, exclude, path)
111 if fm.Len() > 0 {
112 result.SetMapIndex(k, fm)
113 }
114 case reflect.Slice:
115 s := reflect.MakeSlice(v.Type(), 0, v.Len())
116 for i := 0; i < v.Len(); i++ {
117 sliceItem := v.Index(i)
118 if actualValue(sliceItem).Kind() == reflect.Map {
119 fm := filterMap(actualValue(sliceItem), include, exclude, path)
120 if fm.Len() > 0 {
121 s = reflect.Append(s, fm)
122 }
123 } else if match {
124 s = reflect.Append(s, sliceItem)
125 }
126 }
127 if s.Len() > 0 {
128 result.SetMapIndex(k, s)
129 }
130 default:
131 if match {
132 result.SetMapIndex(k, v)
133 }
134 }
135 }
136
137 return result
138}

Callers 1

FilterMapFunction · 0.85

Calls 2

actualValueFunction · 0.85
LenMethod · 0.45

Tested by

no test coverage detected