in include/yyjson/yyjson.h [7687:7715]
yyjson_api_inline bool yyjson_ptr_ctx_remove(yyjson_ptr_ctx *ctx) {
yyjson_mut_val *ctn, *pre_key, *pre_val, *cur_key, *cur_val;
size_t len;
if (!ctx || !ctx->ctn || !ctx->pre) return false;
ctn = ctx->ctn;
if (yyjson_mut_is_obj(ctn)) {
pre_key = ctx->pre;
pre_val = pre_key->next;
cur_key = pre_val->next;
cur_val = cur_key->next;
/* remove current key-value */
pre_val->next = cur_val->next;
if (ctn->uni.ptr == cur_key) ctn->uni.ptr = pre_key;
ctx->pre = NULL;
ctx->old = cur_val;
} else {
pre_val = ctx->pre;
cur_val = pre_val->next;
/* remove current key-value */
pre_val->next = cur_val->next;
if (ctn->uni.ptr == cur_val) ctn->uni.ptr = pre_val;
ctx->pre = NULL;
ctx->old = cur_val;
}
len = unsafe_yyjson_get_len(ctn) - 1;
if (len == 0) ctn->uni.ptr = NULL;
unsafe_yyjson_set_len(ctn, len);
return true;
}