Render a value to text. */
| 1361 | |
| 1362 | /* Render a value to text. */ |
| 1363 | static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) |
| 1364 | { |
| 1365 | unsigned char *output = NULL; |
| 1366 | |
| 1367 | if ((item == NULL) || (output_buffer == NULL)) |
| 1368 | { |
| 1369 | return false; |
| 1370 | } |
| 1371 | |
| 1372 | switch ((item->type) & 0xFF) |
| 1373 | { |
| 1374 | case cJSON_NULL: |
| 1375 | output = ensure(output_buffer, 5); |
| 1376 | if (output == NULL) |
| 1377 | { |
| 1378 | return false; |
| 1379 | } |
| 1380 | strcpy((char*)output, "null"); |
| 1381 | return true; |
| 1382 | |
| 1383 | case cJSON_False: |
| 1384 | output = ensure(output_buffer, 6); |
| 1385 | if (output == NULL) |
| 1386 | { |
| 1387 | return false; |
| 1388 | } |
| 1389 | strcpy((char*)output, "false"); |
| 1390 | return true; |
| 1391 | |
| 1392 | case cJSON_True: |
| 1393 | output = ensure(output_buffer, 5); |
| 1394 | if (output == NULL) |
| 1395 | { |
| 1396 | return false; |
| 1397 | } |
| 1398 | strcpy((char*)output, "true"); |
| 1399 | return true; |
| 1400 | |
| 1401 | case cJSON_Number: |
| 1402 | return print_number(item, output_buffer); |
| 1403 | |
| 1404 | case cJSON_Raw: |
| 1405 | { |
| 1406 | size_t raw_length = 0; |
| 1407 | if (item->valuestring == NULL) |
| 1408 | { |
| 1409 | return false; |
| 1410 | } |
| 1411 | |
| 1412 | raw_length = strlen(item->valuestring) + sizeof(""); |
| 1413 | output = ensure(output_buffer, raw_length); |
| 1414 | if (output == NULL) |
| 1415 | { |
| 1416 | return false; |
| 1417 | } |
| 1418 | memcpy(output, item->valuestring, raw_length); |
| 1419 | return true; |
| 1420 | } |
no test coverage detected