MCPcopy Create free account
hub / github.com/Tencent/Hardcoder / print_value

Function print_value

libapp2sys/src/main/cpp/cjson/cJSON.c:1270–1342  ·  view source on GitHub ↗

Render a value to text. */

Source from the content-addressed store, hash-verified

1268
1269/* Render a value to text. */
1270static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer)
1271{
1272 unsigned char *output = NULL;
1273
1274 if ((item == NULL) || (output_buffer == NULL))
1275 {
1276 return false;
1277 }
1278
1279 switch ((item->type) & 0xFF)
1280 {
1281 case cJSON_NULL:
1282 output = ensure(output_buffer, 5);
1283 if (output == NULL)
1284 {
1285 return false;
1286 }
1287
1288 strncpy((char*)output, "null", 5);
1289 return true;
1290
1291 case cJSON_False:
1292 output = ensure(output_buffer, 6);
1293 if (output == NULL)
1294 {
1295 return false;
1296 }
1297 strncpy((char*)output, "false", 6);
1298 return true;
1299
1300 case cJSON_True:
1301 output = ensure(output_buffer, 5);
1302 if (output == NULL)
1303 {
1304 return false;
1305 }
1306 strncpy((char*)output, "true", 5);
1307 return true;
1308
1309 case cJSON_Number:
1310 return print_number(item, output_buffer);
1311
1312 case cJSON_Raw:
1313 {
1314 size_t raw_length = 0;
1315 if (item->valuestring == NULL)
1316 {
1317 return false;
1318 }
1319
1320 raw_length = strlen(item->valuestring) + sizeof("");
1321 output = ensure(output_buffer, raw_length);
1322 if (output == NULL)
1323 {
1324 return false;
1325 }
1326 memcpy(output, item->valuestring, raw_length);
1327 return true;

Callers 5

printFunction · 0.85
cJSON_PrintBufferedFunction · 0.85
cJSON_PrintPreallocatedFunction · 0.85
print_arrayFunction · 0.85
print_objectFunction · 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