MCPcopy Create free account
hub / github.com/acl-dev/acl / cJSON_Duplicate

Function cJSON_Duplicate

lib_acl/samples/json/json5/cJSON.cpp:708–733  ·  view source on GitHub ↗

Duplication */

Source from the content-addressed store, hash-verified

706
707/* Duplication */
708cJSON *cJSON_Duplicate(cJSON *item,int recurse)
709{
710 cJSON *newitem,*cptr,*nptr=0,*newchild;
711 /* Bail on bad ptr */
712 if (!item) return 0;
713 /* Create new item */
714 newitem=cJSON_New_Item();
715 if (!newitem) return 0;
716 /* Copy over all vars */
717 newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble;
718 if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}}
719 if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}}
720 /* If non-recursive, then we're done! */
721 if (!recurse) return newitem;
722 /* Walk the ->next chain for the child. */
723 cptr=item->child;
724 while (cptr)
725 {
726 newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */
727 if (!newchild) {cJSON_Delete(newitem);return 0;}
728 if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */
729 else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */
730 cptr=cptr->next;
731 }
732 return newitem;
733}
734
735void cJSON_Minify(char *json)
736{

Callers

nothing calls this directly

Calls 3

cJSON_New_ItemFunction · 0.85
cJSON_strdupFunction · 0.85
cJSON_DeleteFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…