1161 } |
1161 } |
1162 |
1162 |
1163 CxIterator cxJsonArrIter(const CxJsonValue *value) { |
1163 CxIterator cxJsonArrIter(const CxJsonValue *value) { |
1164 return cxIteratorPtr( |
1164 return cxIteratorPtr( |
1165 value->value.array.array, |
1165 value->value.array.array, |
1166 value->value.array.array_size |
1166 value->value.array.array_size, |
|
1167 true // arrays need to keep order |
1167 ); |
1168 ); |
1168 } |
1169 } |
1169 |
1170 |
1170 CxIterator cxJsonObjIter(const CxJsonValue *value) { |
1171 CxIterator cxJsonObjIter(const CxJsonValue *value) { |
1171 return cxIterator( |
1172 return cxIterator( |
1172 value->value.object.values, |
1173 value->value.object.values, |
1173 sizeof(CxJsonObjValue), |
1174 sizeof(CxJsonObjValue), |
1174 value->value.object.values_size |
1175 value->value.object.values_size, |
|
1176 true // TODO: objects do not always need to keep order |
1175 ); |
1177 ); |
1176 } |
1178 } |
1177 |
1179 |
1178 CxJsonValue *cx_json_obj_get(const CxJsonValue *value, cxstring name) { |
1180 CxJsonValue *cx_json_obj_get(const CxJsonValue *value, cxstring name) { |
1179 size_t index = json_find_objvalue(value, name); |
1181 size_t index = json_find_objvalue(value, name); |
1189 if (index >= value->value.object.values_size) { |
1191 if (index >= value->value.object.values_size) { |
1190 return NULL; |
1192 return NULL; |
1191 } else { |
1193 } else { |
1192 CxJsonObjValue kv = value->value.object.values[index]; |
1194 CxJsonObjValue kv = value->value.object.values[index]; |
1193 cx_strfree_a(value->allocator, &kv.name); |
1195 cx_strfree_a(value->allocator, &kv.name); |
1194 // TODO: replace with cx_array_remove() |
1196 // TODO: replace with cx_array_remove() / cx_array_remove_fast() |
1195 value->value.object.values_size--; |
1197 value->value.object.values_size--; |
1196 memmove(value->value.object.values + index, value->value.object.values + index + 1, (value->value.object.values_size - index) * sizeof(CxJsonObjValue)); |
1198 memmove(value->value.object.values + index, value->value.object.values + index + 1, (value->value.object.values_size - index) * sizeof(CxJsonObjValue)); |
1197 return kv.value; |
1199 return kv.value; |
1198 } |
1200 } |
1199 } |
1201 } |