| 77 | } |
| 78 | |
| 79 | FormattedJson Star::addOrSet(bool add, |
| 80 | JsonPath::PathPtr path, |
| 81 | FormattedJson const& input, |
| 82 | InsertLocation insertLocation, |
| 83 | FormattedJson const& value) { |
| 84 | JsonPath::EmptyPathOp<FormattedJson> emptyPathOp = [&value, add](FormattedJson const& document) { |
| 85 | if (!add || document.type() == Json::Type::Null) |
| 86 | return value; |
| 87 | throw JsonException("Cannot add a value to the entire document, it is not empty."); |
| 88 | }; |
| 89 | JsonPath::ObjectOp<FormattedJson> objectOp = [&value, &insertLocation]( |
| 90 | FormattedJson const& object, String const& key) { |
| 91 | if (insertLocation.is<AtBeginning>()) |
| 92 | return object.prepend(key, value); |
| 93 | if (insertLocation.is<AtEnd>()) |
| 94 | return object.append(key, value); |
| 95 | if (insertLocation.is<BeforeKey>()) |
| 96 | return object.insertBefore(key, value, insertLocation.get<BeforeKey>().key); |
| 97 | if (insertLocation.is<AfterKey>()) |
| 98 | return object.insertAfter(key, value, insertLocation.get<AfterKey>().key); |
| 99 | return object.set(key, value); |
| 100 | }; |
| 101 | JsonPath::ArrayOp<FormattedJson> arrayOp = [&value, add](FormattedJson const& array, Maybe<size_t> i) { |
| 102 | if (i.isValid()) { |
| 103 | if (add) |
| 104 | return array.insert(*i, value); |
| 105 | return array.set(*i, value); |
| 106 | } |
| 107 | return array.append(value); |
| 108 | }; |
| 109 | return path->apply(input, emptyPathOp, objectOp, arrayOp); |
| 110 | } |
| 111 | |
| 112 | void forEachFileRecursive(String const& directory, function<void(String)> func) { |
| 113 | for (pair<String, bool> entry : File::dirList(directory)) { |
nothing calls this directly
no test coverage detected