| 4120 | } |
| 4121 | |
| 4122 | Value Path::resolve(const Value& root, const Value& defaultValue) const { |
| 4123 | const Value* node = &root; |
| 4124 | for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) { |
| 4125 | const PathArgument& arg = *it; |
| 4126 | if (arg.kind_ == PathArgument::kindIndex) { |
| 4127 | if (!node->isArray() || !node->isValidIndex(arg.index_)) |
| 4128 | return defaultValue; |
| 4129 | node = &((*node)[arg.index_]); |
| 4130 | } else if (arg.kind_ == PathArgument::kindKey) { |
| 4131 | if (!node->isObject()) |
| 4132 | return defaultValue; |
| 4133 | node = &((*node)[arg.key_]); |
| 4134 | if (node == &Value::nullSingleton()) |
| 4135 | return defaultValue; |
| 4136 | } |
| 4137 | } |
| 4138 | return *node; |
| 4139 | } |
| 4140 | |
| 4141 | Value& Path::make(Value& root) const { |
| 4142 | Value* node = &root; |
no test coverage detected