| 3905 | void Value::removeMember(const String &key) { removeMember(key.c_str()); } |
| 3906 | |
| 3907 | bool Value::removeIndex(ArrayIndex index, Value *removed) |
| 3908 | { |
| 3909 | if (type() != arrayValue) |
| 3910 | { |
| 3911 | return false; |
| 3912 | } |
| 3913 | CZString key(index); |
| 3914 | auto it = value_.map_->find(key); |
| 3915 | if (it == value_.map_->end()) |
| 3916 | { |
| 3917 | return false; |
| 3918 | } |
| 3919 | if (removed) |
| 3920 | *removed = it->second; |
| 3921 | ArrayIndex oldSize = size(); |
| 3922 | // shift left all items left, into the place of the "removed" |
| 3923 | for (ArrayIndex i = index; i < (oldSize - 1); ++i) |
| 3924 | { |
| 3925 | CZString keey(i); |
| 3926 | (*value_.map_)[keey] = (*this)[i + 1]; |
| 3927 | } |
| 3928 | // erase the last one ("leftover") |
| 3929 | CZString keyLast(oldSize - 1); |
| 3930 | auto itLast = value_.map_->find(keyLast); |
| 3931 | value_.map_->erase(itLast); |
| 3932 | return true; |
| 3933 | } |
| 3934 | |
| 3935 | bool Value::isMember(char const *begin, char const *end) const |
| 3936 | { |