Index gets the i-th item of an array, slice or string. Otherwise it will return NIL.
(i int)
| 298 | // Index gets the i-th item of an array, slice or string. Otherwise |
| 299 | // it will return NIL. |
| 300 | func (v *Value) Index(i int) *Value { |
| 301 | switch v.getResolvedValue().Kind() { |
| 302 | case reflect.Array, reflect.Slice: |
| 303 | if i >= v.Len() { |
| 304 | return AsValue(nil) |
| 305 | } |
| 306 | return AsValue(v.getResolvedValue().Index(i).Interface()) |
| 307 | case reflect.String: |
| 308 | // return AsValue(v.getResolvedValue().Slice(i, i+1).Interface()) |
| 309 | s := v.getResolvedValue().String() |
| 310 | runes := []rune(s) |
| 311 | if i < len(runes) { |
| 312 | return AsValue(string(runes[i])) |
| 313 | } |
| 314 | return AsValue("") |
| 315 | default: |
| 316 | logf("Value.Slice() not available for type: %s\n", v.getResolvedValue().Kind().String()) |
| 317 | return AsValue([]int{}) |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | // Contains checks whether the underlying value (which must be of type struct, map, |
| 322 | // string, array or slice) contains of another Value (e. g. used to check |
no test coverage detected