| 1199 | void Value::removeMember(const String& key) { removeMember(key.c_str()); } |
| 1200 | |
| 1201 | bool Value::removeIndex(ArrayIndex index, Value* removed) { |
| 1202 | if (type() != arrayValue) { |
| 1203 | return false; |
| 1204 | } |
| 1205 | CZString key(index); |
| 1206 | auto it = value_.map_->find(key); |
| 1207 | if (it == value_.map_->end()) { |
| 1208 | return false; |
| 1209 | } |
| 1210 | if (removed) |
| 1211 | *removed = std::move(it->second); |
| 1212 | ArrayIndex oldSize = size(); |
| 1213 | // shift left all items left, into the place of the "removed" |
| 1214 | for (ArrayIndex i = index; i < (oldSize - 1); ++i) { |
| 1215 | CZString keey(i); |
| 1216 | (*value_.map_)[keey] = (*this)[i + 1]; |
| 1217 | } |
| 1218 | // erase the last one ("leftover") |
| 1219 | CZString keyLast(oldSize - 1); |
| 1220 | auto itLast = value_.map_->find(keyLast); |
| 1221 | value_.map_->erase(itLast); |
| 1222 | return true; |
| 1223 | } |
| 1224 | |
| 1225 | bool Value::isMember(char const* begin, char const* end) const { |
| 1226 | Value const* value = find(begin, end); |