Browse Source

reformatting: cJSON_ReplaceItemInObject

Max Bruckner 8 years ago
parent
commit
3a8043273e
1 changed files with 15 additions and 1 deletions
  1. 15 1
      cJSON.c

+ 15 - 1
cJSON.c

@@ -1825,7 +1825,21 @@ void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
     cJSON_Delete(c);
     cJSON_Delete(c);
 }
 }
 
 
-void   cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
+void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem)
+{
+    int i = 0;
+    cJSON *c = object->child;
+    while(c && cJSON_strcasecmp(c->string, string))
+    {
+        i++;
+        c = c->next;
+    }
+    if(c)
+    {
+        newitem->string = cJSON_strdup(string);
+        cJSON_ReplaceItemInArray(object, i, newitem);
+    }
+}
 
 
 /* Create basic types: */
 /* Create basic types: */
 cJSON *cJSON_CreateNull(void)					{cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
 cJSON *cJSON_CreateNull(void)					{cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}