diff --git a/src/cson.c b/src/cson.c index 622e095..019686d 100644 --- a/src/cson.c +++ b/src/cson.c @@ -686,6 +686,41 @@ CsonList* csonListAdd(CsonList *list, void *obj) } +/** + * @brief CSON链表删除节点 + * + * @param list 链表 + * @param obj 节点对象 + * @param freeMem 释放内存 + * @return CsonList 链表 + */ +CsonList *csonListDelete(CsonList *list, void *obj, char freeMem) +{ + CSON_ASSERT(list, return NULL); + + CsonList head = {0}; + head.next = list; + CsonList *p = &head; + CsonList *tmp; + while (p->next) + { + if (p->next->obj && p->next->obj == obj) + { + tmp = p->next; + p->next = p->next->next ? p->next->next : NULL; + if (freeMem) + { + cson.free(tmp->obj); + cson.free(tmp); + } + break; + } + p = p->next; + } + return head.next; +} + + /** * @brief CSON新字符串 * diff --git a/src/cson.h b/src/cson.h index 02c73c1..cb85174 100644 --- a/src/cson.h +++ b/src/cson.h @@ -228,7 +228,7 @@ extern CsonModel csonBasicListModel[]; /**< 基础类型链表数据模型 */ */ #define CSON_ASSERT(expr, action) \ if (!(expr)) { \ - printf(#expr " assert failed at file: %s, line: %d", __FILE__, __LINE__); \ + printf(#expr " assert failed at file: %s, line: %d\r\n", __FILE__, __LINE__); \ action; \ } @@ -368,6 +368,16 @@ void csonFreeJson(const char *jsonStr); */ CsonList* csonListAdd(CsonList *list, void *obj); +/** + * @brief CSON链表删除节点 + * + * @param list 链表 + * @param obj 节点对象 + * @param freeMem 释放内存 + * @return CsonList 链表 + */ +CsonList *csonListDelete(CsonList *list, void *obj, char freeMem); + /** * @brief CSON新字符串 *