MCPcopy Create free account
hub / github.com/DaveGamble/cJSON / print_value

Function print_value

cJSON.c:1418–1489  ·  view source on GitHub ↗

Render a value to text. */

Source from the content-addressed store, hash-verified

1416
1417/* Render a value to text. */
1418static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer)
1419{
1420 unsigned char *output = NULL;
1421
1422 if ((item == NULL) || (output_buffer == NULL))
1423 {
1424 return false;
1425 }
1426
1427 switch ((item->type) & 0xFF)
1428 {
1429 case cJSON_NULL:
1430 output = ensure(output_buffer, 5);
1431 if (output == NULL)
1432 {
1433 return false;
1434 }
1435 strcpy((char*)output, "null");
1436 return true;
1437
1438 case cJSON_False:
1439 output = ensure(output_buffer, 6);
1440 if (output == NULL)
1441 {
1442 return false;
1443 }
1444 strcpy((char*)output, "false");
1445 return true;
1446
1447 case cJSON_True:
1448 output = ensure(output_buffer, 5);
1449 if (output == NULL)
1450 {
1451 return false;
1452 }
1453 strcpy((char*)output, "true");
1454 return true;
1455
1456 case cJSON_Number:
1457 return print_number(item, output_buffer);
1458
1459 case cJSON_Raw:
1460 {
1461 size_t raw_length = 0;
1462 if (item->valuestring == NULL)
1463 {
1464 return false;
1465 }
1466
1467 raw_length = strlen(item->valuestring) + sizeof("");
1468 output = ensure(output_buffer, raw_length);
1469 if (output == NULL)
1470 {
1471 return false;
1472 }
1473 memcpy(output, item->valuestring, raw_length);
1474 return true;
1475 }

Callers 6

printFunction · 0.85
cJSON_PrintBufferedFunction · 0.85
cJSON_PrintPreallocatedFunction · 0.85
print_arrayFunction · 0.85
print_objectFunction · 0.85
assert_print_valueFunction · 0.85

Calls 5

ensureFunction · 0.85
print_numberFunction · 0.85
print_stringFunction · 0.85
print_arrayFunction · 0.85
print_objectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…