| 266 | } |
| 267 | |
| 268 | func setIndex(list []interface{}, index int, val interface{}) (l2 []interface{}, err error) { |
| 269 | // There are possible index values that are out of range on a target system |
| 270 | // causing a panic. This will catch the panic and return an error instead. |
| 271 | // The value of the index that causes a panic varies from system to system. |
| 272 | defer func() { |
| 273 | if r := recover(); r != nil { |
| 274 | err = fmt.Errorf("error processing index %d: %s", index, r) |
| 275 | } |
| 276 | }() |
| 277 | |
| 278 | if index < 0 { |
| 279 | return list, fmt.Errorf("negative %d index not allowed", index) |
| 280 | } |
| 281 | if len(list) <= index { |
| 282 | newlist := make([]interface{}, index+1) |
| 283 | copy(newlist, list) |
| 284 | list = newlist |
| 285 | } |
| 286 | switch reflect.TypeOf(val).Kind() { |
| 287 | case reflect.String: |
| 288 | if len(val.(string)) > 0 { |
| 289 | list[index] = val |
| 290 | } else { |
| 291 | list[index] = nil |
| 292 | } |
| 293 | default: |
| 294 | list[index] = val |
| 295 | } |
| 296 | return list, nil |
| 297 | } |
| 298 | |
| 299 | func (t *parser) keyIndex() (int, error) { |
| 300 | // First, get the key. |