Duplication */
| 706 | |
| 707 | /* Duplication */ |
| 708 | cJSON *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 | |
| 735 | void cJSON_Minify(char *json) |
| 736 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…