| 147 | } |
| 148 | |
| 149 | void JSONDoc::cleanOps(json_spirit::mObject& obj) { |
| 150 | auto kv = obj.begin(); |
| 151 | while (kv != obj.end()) { |
| 152 | if (kv->second.type() == json_spirit::obj_type) { |
| 153 | json_spirit::mObject& o = kv->second.get_obj(); |
| 154 | std::string op = getOperator(o); |
| 155 | // If an operator was found, replace object with its value. |
| 156 | if (!op.empty()) { |
| 157 | // The "count_keys" operator needs special handling |
| 158 | if (op == "$count_keys") { |
| 159 | int count = 1; |
| 160 | if (o.at(op).type() == json_spirit::obj_type) |
| 161 | count = o.at(op).get_obj().size(); |
| 162 | kv->second = count; |
| 163 | } else if (op == "$expires") { |
| 164 | uint64_t version = 0; |
| 165 | JSONDoc(o).tryGet("version", version); |
| 166 | if (version == 0 || version > JSONDoc::expires_reference_version) |
| 167 | kv->second = o.at(op); |
| 168 | else { |
| 169 | // Thing is expired so competely remove its key from the enclosing Object |
| 170 | auto tmp = kv; |
| 171 | ++kv; |
| 172 | obj.erase(tmp); |
| 173 | } |
| 174 | } else // For others just move the value to replace the operator object |
| 175 | kv->second = o.at(op); |
| 176 | // Don't advance kv because the new value could also be an operator |
| 177 | continue; |
| 178 | } else { |
| 179 | // It's not an operator, just a regular object so clean it too. |
| 180 | cleanOps(o); |
| 181 | } |
| 182 | } |
| 183 | ++kv; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void JSONDoc::mergeInto(json_spirit::mObject& dst, const json_spirit::mObject& src) { |
| 188 | for (auto& i : src) { |
no test coverage detected