From fdfd87d6ee20d965d13c8fd047bdeda90c62f327 Mon Sep 17 00:00:00 2001 From: "Dominick C. Pastore" Date: Sat, 9 May 2020 11:06:17 -0400 Subject: [PATCH] Add macros to iterate over array item by item --- cJSON.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cJSON.h b/cJSON.h index 0c6c8e0..aa58e84 100644 --- a/cJSON.h +++ b/cJSON.h @@ -279,8 +279,10 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); -/* Macro for iterating over an array or object */ +/* Macros for iterating over an array or object */ #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) +#define cJSON_ArrayFirst(element, array) (element = (array != NULL) ? (array)->child : NULL) +#define cJSON_ArrayNext(element) (element = element->next) /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ CJSON_PUBLIC(void *) cJSON_malloc(size_t size);