MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / print_array

Function print_array

lib/cJSON.c:1243–1409  ·  view source on GitHub ↗

Render an array to text */

Source from the content-addressed store, hash-verified

1241
1242/* Render an array to text */
1243static unsigned char *print_array(const cJSON *item, size_t depth, cjbool fmt, printbuffer *p)
1244{
1245 unsigned char **entries;
1246 unsigned char *out = NULL;
1247 unsigned char *ptr = NULL;
1248 unsigned char *ret = NULL;
1249 size_t len = 5;
1250 cJSON *child = item->child;
1251 size_t numentries = 0;
1252 size_t i = 0;
1253 cjbool fail = false;
1254 size_t tmplen = 0;
1255
1256 /* How many entries in the array? */
1257 while (child)
1258 {
1259 numentries++;
1260 child = child->next;
1261 }
1262
1263 /* Explicitly handle numentries == 0 */
1264 if (!numentries)
1265 {
1266 if (p)
1267 {
1268 out = ensure(p, 3);
1269 }
1270 else
1271 {
1272 out = (unsigned char*)cJSON_malloc(3);
1273 }
1274 if (out)
1275 {
1276 strcpy((char*)out, "[]");
1277 }
1278
1279 return out;
1280 }
1281
1282 if (p)
1283 {
1284 /* Compose the output array. */
1285 /* opening square bracket */
1286 i = p->offset;
1287 ptr = ensure(p, 1);
1288 if (!ptr)
1289 {
1290 return NULL;
1291 }
1292 *ptr = '[';
1293 p->offset++;
1294
1295 child = item->child;
1296 while (child && !fail)
1297 {
1298 if (!print_value(child, depth + 1, fmt, p))
1299 {
1300 return NULL;

Callers 1

print_valueFunction · 0.70

Calls 3

ensureFunction · 0.85
print_valueFunction · 0.70
updateFunction · 0.70

Tested by

no test coverage detected