Render a value to text. */
| 1281 | |
| 1282 | /* Render a value to text. */ |
| 1283 | static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) |
| 1284 | { |
| 1285 | unsigned char *output = NULL; |
| 1286 | |
| 1287 | if ((item == NULL) || (output_buffer == NULL)) |
| 1288 | { |
| 1289 | return false; |
| 1290 | } |
| 1291 | |
| 1292 | switch ((item->type) & 0xFF) |
| 1293 | { |
| 1294 | case cJSON_NULL: |
| 1295 | output = ensure(output_buffer, 5); |
| 1296 | if (output == NULL) |
| 1297 | { |
| 1298 | return false; |
| 1299 | } |
| 1300 | strcpy((char*)output, "null"); |
| 1301 | return true; |
| 1302 | |
| 1303 | case cJSON_False: |
| 1304 | output = ensure(output_buffer, 6); |
| 1305 | if (output == NULL) |
| 1306 | { |
| 1307 | return false; |
| 1308 | } |
| 1309 | strcpy((char*)output, "false"); |
| 1310 | return true; |
| 1311 | |
| 1312 | case cJSON_True: |
| 1313 | output = ensure(output_buffer, 5); |
| 1314 | if (output == NULL) |
| 1315 | { |
| 1316 | return false; |
| 1317 | } |
| 1318 | strcpy((char*)output, "true"); |
| 1319 | return true; |
| 1320 | |
| 1321 | case cJSON_Number: |
| 1322 | return print_number(item, output_buffer); |
| 1323 | |
| 1324 | case cJSON_Raw: |
| 1325 | { |
| 1326 | size_t raw_length = 0; |
| 1327 | if (item->valuestring == NULL) |
| 1328 | { |
| 1329 | return false; |
| 1330 | } |
| 1331 | |
| 1332 | raw_length = strlen(item->valuestring) + sizeof(""); |
| 1333 | output = ensure(output_buffer, raw_length); |
| 1334 | if (output == NULL) |
| 1335 | { |
| 1336 | return false; |
| 1337 | } |
| 1338 | memcpy(output, item->valuestring, raw_length); |
| 1339 | return true; |
| 1340 | } |
no test coverage detected