| 293 | |
| 294 | template <typename Jsonlike> |
| 295 | Jsonlike pathRemove(Jsonlike const& base, PathParser parser, String const& path) { |
| 296 | EmptyPathOp<Jsonlike> emptyPathOp = [](Jsonlike const&) { return Json{}; }; |
| 297 | ObjectOp<Jsonlike> objectOp = [](Jsonlike const& object, String const& key) { |
| 298 | if (!object.contains(key)) |
| 299 | throw TraversalException::format("Could not find \"{}\" to remove", key); |
| 300 | return object.eraseKey(key); |
| 301 | }; |
| 302 | ArrayOp<Jsonlike> arrayOp = [](Jsonlike const& array, Maybe<size_t> i) { |
| 303 | if (i.isValid()) |
| 304 | return array.eraseIndex(*i); |
| 305 | throw TraversalException("Could not remove element after end of array"); |
| 306 | }; |
| 307 | return pathApply(base, parser, path, genericObjectArrayOp(path, emptyPathOp, objectOp, arrayOp)); |
| 308 | } |
| 309 | |
| 310 | template <typename Jsonlike> |
| 311 | Jsonlike pathAdd(Jsonlike const& base, PathParser parser, String const& path, Jsonlike const& value) { |
no test coverage detected