MCPcopy
hub / github.com/lmorg/murex / itoIndexMap

Function itoIndexMap

lang/define_index_objects.go:102–204  ·  view source on GitHub ↗
(p *Process, params []string, v map[K]V, marshaller func(any) ([]byte, error))

Source from the content-addressed store, hash-verified

100}
101
102func itoIndexMap[K comparable, V indexValueT](p *Process, params []string, v map[K]V, marshaller func(any) ([]byte, error)) error {
103 var (
104 objArray []any
105 objMap = make(map[string]any)
106 obj any
107 err error
108 )
109
110 for i := range params {
111 if len(params[i]) > 2 && params[i][0] == '[' && params[i][len(params[i])-1] == ']' {
112 obj, err = ElementLookup(v, params[i][1:len(params[i])-1], "")
113 if err != nil {
114 return err
115 }
116 params[i] = params[i][2 : len(params[i])-1]
117
118 } else {
119 var (
120 iString int
121 key any
122 ok bool
123 )
124
125 for {
126 switch iString {
127 case 0:
128 key = params[i]
129 case 1:
130 key = strings.Title(params[i])
131 case 2:
132 key = strings.ToLower(params[i])
133 case 3:
134 key = strings.ToUpper(params[i])
135 default:
136 return fmt.Errorf("key '%s' not found", params[i])
137 }
138
139 obj, ok = v[key.(K)]
140 if ok {
141 break
142 }
143 iString++
144 }
145 }
146
147 if len(params) > 1 {
148 if modver.Get(p.FileRef.Source.Module).Compare(semver.Version8_0).IsLessThan() {
149 objArray = append(objArray, obj)
150 } else {
151 objMap[params[i]] = obj
152 }
153
154 } else {
155 switch obj := obj.(type) {
156 case nil:
157 p.Stdout.SetDataType(types.Null)
158 case bool:
159 p.Stdout.SetDataType(types.Boolean)

Callers 1

itoIndexFunction · 0.85

Calls 8

GetFunction · 0.92
FloatToStringFunction · 0.92
ElementLookupFunction · 0.85
IsLessThanMethod · 0.80
SetDataTypeMethod · 0.65
WriteMethod · 0.65
WritelnMethod · 0.65
CompareMethod · 0.45

Tested by

no test coverage detected