| 4347 | } |
| 4348 | |
| 4349 | Value Path::resolve(const Value &root, const Value &defaultValue) const |
| 4350 | { |
| 4351 | const Value *node = &root; |
| 4352 | for (const auto &arg : args_) |
| 4353 | { |
| 4354 | if (arg.kind_ == PathArgument::kindIndex) |
| 4355 | { |
| 4356 | if (!node->isArray() || !node->isValidIndex(arg.index_)) |
| 4357 | return defaultValue; |
| 4358 | node = &((*node)[arg.index_]); |
| 4359 | } |
| 4360 | else if (arg.kind_ == PathArgument::kindKey) |
| 4361 | { |
| 4362 | if (!node->isObject()) |
| 4363 | return defaultValue; |
| 4364 | node = &((*node)[arg.key_]); |
| 4365 | if (node == &Value::nullSingleton()) |
| 4366 | return defaultValue; |
| 4367 | } |
| 4368 | } |
| 4369 | return *node; |
| 4370 | } |
| 4371 | |
| 4372 | Value &Path::make(Value &root) const |
| 4373 | { |
no test coverage detected