| 1258 | } |
| 1259 | |
| 1260 | bool Value::removeIndex(ArrayIndex index, Value* removed) { |
| 1261 | if (type_ != arrayValue) { |
| 1262 | return false; |
| 1263 | } |
| 1264 | CZString key(index); |
| 1265 | auto it = value_.map_->find(key); |
| 1266 | if (it == value_.map_->end()) { |
| 1267 | return false; |
| 1268 | } |
| 1269 | if (removed) |
| 1270 | *removed = it->second; |
| 1271 | ArrayIndex oldSize = size(); |
| 1272 | // shift left all items left, into the place of the "removed" |
| 1273 | for (ArrayIndex i = index; i < (oldSize - 1); ++i) { |
| 1274 | CZString keey(i); |
| 1275 | (*value_.map_)[keey] = (*this)[i + 1]; |
| 1276 | } |
| 1277 | // erase the last one ("leftover") |
| 1278 | CZString keyLast(oldSize - 1); |
| 1279 | auto itLast = value_.map_->find(keyLast); |
| 1280 | value_.map_->erase(itLast); |
| 1281 | return true; |
| 1282 | } |
| 1283 | |
| 1284 | #ifdef JSON_USE_CPPTL |
| 1285 | Value Value::get(const CppTL::ConstString& key, |
no test coverage detected