MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / pathRemove

Function pathRemove

source/core/StarJsonPath.hpp:295–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) {

Callers 2

removeMethod · 0.85
erasePathMethod · 0.85

Calls 7

pathApplyFunction · 0.85
genericObjectArrayOpFunction · 0.85
isValidMethod · 0.80
formatFunction · 0.70
containsMethod · 0.45
eraseKeyMethod · 0.45
eraseIndexMethod · 0.45

Tested by

no test coverage detected