| 1366 | #endif |
| 1367 | |
| 1368 | bool Value::removeIndex(ArrayIndex index, Value* removed) { |
| 1369 | if (type() != arrayValue) { |
| 1370 | return false; |
| 1371 | } |
| 1372 | CZString key(index); |
| 1373 | auto it = value_.map_->find(key); |
| 1374 | if (it == value_.map_->end()) { |
| 1375 | return false; |
| 1376 | } |
| 1377 | if (removed) |
| 1378 | *removed = std::move(it->second); |
| 1379 | ArrayIndex oldSize = size(); |
| 1380 | // shift left all items left, into the place of the "removed" |
| 1381 | for (ArrayIndex i = index; i < (oldSize - 1); ++i) { |
| 1382 | CZString keey(i); |
| 1383 | (*value_.map_)[keey] = (*this)[i + 1]; |
| 1384 | } |
| 1385 | // erase the last one ("leftover") |
| 1386 | CZString keyLast(oldSize - 1); |
| 1387 | auto itLast = value_.map_->find(keyLast); |
| 1388 | value_.map_->erase(itLast); |
| 1389 | return true; |
| 1390 | } |
| 1391 | |
| 1392 | bool Value::isMember(char const* begin, char const* end) const { |
| 1393 | Value const* value = find(begin, end); |