--- a/src/json.c Fri Dec 20 15:15:18 2024 +0100 +++ b/src/json.c Fri Dec 20 16:51:01 2024 +0100 @@ -674,6 +674,39 @@ return value->value.array.array[index]; } +static void *cx_json_iter_current(const void *it) { + const CxIterator *iter = it; + return *(CxJsonValue**)iter->elem_handle; +} + +static bool cx_json_iter_valid(const void *it) { + const CxIterator *iter = it; + return iter->index < iter->elem_count; +} + +static void cx_json_iter_next(void *it) { + CxIterator *iter = it; + iter->index++; + iter->elem_handle = (char *) iter->elem_handle + sizeof(void *); +} + +CxIterator cxJsonArrIter(const CxJsonValue *value) { + CxIterator iter; + + iter.index = 0; + iter.elem_count = value->value.array.array_size; + iter.src_handle.m = value->value.array.array; + iter.elem_handle = iter.src_handle.m; + iter.elem_size = sizeof(CxJsonValue*); + iter.base.valid = cx_json_iter_valid; + iter.base.current = cx_json_iter_current; + iter.base.next = cx_json_iter_next; + iter.base.remove = false; + iter.base.mutating = false; + + return iter; +} + CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { const CxJsonObject *obj = &(value->value.object); // TODO: think about sorting the object so that we can use binary search here