Render a value to text. */
| 1378 | |
| 1379 | /* Render a value to text. */ |
| 1380 | static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) |
| 1381 | { |
| 1382 | unsigned char *output = NULL; |
| 1383 | |
| 1384 | if ((item == NULL) || (output_buffer == NULL)) |
| 1385 | { |
| 1386 | return false; |
| 1387 | } |
| 1388 | |
| 1389 | switch ((item->type) & 0xFF) |
| 1390 | { |
| 1391 | case cJSON_NULL: |
| 1392 | output = ensure(output_buffer, 5); |
| 1393 | if (output == NULL) |
| 1394 | { |
| 1395 | return false; |
| 1396 | } |
| 1397 | strcpy((char*)output, "null"); |
| 1398 | return true; |
| 1399 | |
| 1400 | case cJSON_False: |
| 1401 | output = ensure(output_buffer, 6); |
| 1402 | if (output == NULL) |
| 1403 | { |
| 1404 | return false; |
| 1405 | } |
| 1406 | strcpy((char*)output, "false"); |
| 1407 | return true; |
| 1408 | |
| 1409 | case cJSON_True: |
| 1410 | output = ensure(output_buffer, 5); |
| 1411 | if (output == NULL) |
| 1412 | { |
| 1413 | return false; |
| 1414 | } |
| 1415 | strcpy((char*)output, "true"); |
| 1416 | return true; |
| 1417 | |
| 1418 | case cJSON_Number: |
| 1419 | return print_number(item, output_buffer); |
| 1420 | |
| 1421 | case cJSON_Raw: |
| 1422 | { |
| 1423 | size_t raw_length = 0; |
| 1424 | if (item->valuestring == NULL) |
| 1425 | { |
| 1426 | return false; |
| 1427 | } |
| 1428 | |
| 1429 | raw_length = strlen(item->valuestring) + sizeof(""); |
| 1430 | output = ensure(output_buffer, raw_length); |
| 1431 | if (output == NULL) |
| 1432 | { |
| 1433 | return false; |
| 1434 | } |
| 1435 | memcpy(output, item->valuestring, raw_length); |
| 1436 | return true; |
| 1437 | } |
no test coverage detected