Build an array from input text. */
| 1167 | |
| 1168 | /* Build an array from input text. */ |
| 1169 | static const unsigned char *parse_array(cJSON *item, const unsigned char *value, const unsigned char **ep) |
| 1170 | { |
| 1171 | cJSON *child = NULL; |
| 1172 | if (*value != '[') |
| 1173 | { |
| 1174 | /* not an array! */ |
| 1175 | *ep = value; |
| 1176 | goto fail; |
| 1177 | } |
| 1178 | |
| 1179 | item->type = cJSON_Array; |
| 1180 | value = skip(value + 1); |
| 1181 | if (*value == ']') |
| 1182 | { |
| 1183 | /* empty array. */ |
| 1184 | return value + 1; |
| 1185 | } |
| 1186 | |
| 1187 | item->child = child = cJSON_New_Item(); |
| 1188 | if (!item->child) |
| 1189 | { |
| 1190 | /* memory fail */ |
| 1191 | goto fail; |
| 1192 | } |
| 1193 | /* skip any spacing, get the value. */ |
| 1194 | value = skip(parse_value(child, skip(value), ep)); |
| 1195 | if (!value) |
| 1196 | { |
| 1197 | goto fail; |
| 1198 | } |
| 1199 | |
| 1200 | /* loop through the comma separated array elements */ |
| 1201 | while (*value == ',') |
| 1202 | { |
| 1203 | cJSON *new_item = NULL; |
| 1204 | if (!(new_item = cJSON_New_Item())) |
| 1205 | { |
| 1206 | /* memory fail */ |
| 1207 | goto fail; |
| 1208 | } |
| 1209 | /* add new item to end of the linked list */ |
| 1210 | child->next = new_item; |
| 1211 | new_item->prev = child; |
| 1212 | child = new_item; |
| 1213 | |
| 1214 | /* go to the next comma */ |
| 1215 | value = skip(parse_value(child, skip(value + 1), ep)); |
| 1216 | if (!value) |
| 1217 | { |
| 1218 | /* memory fail */ |
| 1219 | goto fail; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | if (*value == ']') |
| 1224 | { |
| 1225 | /* end of array */ |
| 1226 | return value + 1; |
no test coverage detected