| 1821 | } |
| 1822 | |
| 1823 | Value Path::resolve(const Value& root, const Value& defaultValue) const { |
| 1824 | const Value* node = &root; |
| 1825 | for (const auto& arg : args_) { |
| 1826 | if (arg.kind_ == PathArgument::kindIndex) { |
| 1827 | if (!node->isArray() || !node->isValidIndex(arg.index_)) |
| 1828 | return defaultValue; |
| 1829 | node = &((*node)[arg.index_]); |
| 1830 | } else if (arg.kind_ == PathArgument::kindKey) { |
| 1831 | if (!node->isObject()) |
| 1832 | return defaultValue; |
| 1833 | node = &((*node)[arg.key_]); |
| 1834 | if (node == &Value::nullSingleton()) |
| 1835 | return defaultValue; |
| 1836 | } |
| 1837 | } |
| 1838 | return *node; |
| 1839 | } |
| 1840 | |
| 1841 | Value& Path::make(Value& root) const { |
| 1842 | Value* node = &root; |
nothing calls this directly
no test coverage detected