| 4106 | } |
| 4107 | |
| 4108 | Value Path::resolve(const Value& root, const Value& defaultValue) const { |
| 4109 | const Value* node = &root; |
| 4110 | for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) { |
| 4111 | const PathArgument& arg = *it; |
| 4112 | if (arg.kind_ == PathArgument::kindIndex) { |
| 4113 | if (!node->isArray() || !node->isValidIndex(arg.index_)) |
| 4114 | return defaultValue; |
| 4115 | node = &((*node)[arg.index_]); |
| 4116 | } else if (arg.kind_ == PathArgument::kindKey) { |
| 4117 | if (!node->isObject()) |
| 4118 | return defaultValue; |
| 4119 | node = &((*node)[arg.key_]); |
| 4120 | if (node == &Value::nullSingleton()) |
| 4121 | return defaultValue; |
| 4122 | } |
| 4123 | } |
| 4124 | return *node; |
| 4125 | } |
| 4126 | |
| 4127 | Value& Path::make(Value& root) const { |
| 4128 | Value* node = &root; |
no test coverage detected