MCPcopy Index your code
hub / github.com/armink/struct2json / print_value

Function print_value

struct2json/src/cJSON.c:373–404  ·  view source on GitHub ↗

Render a value to text. */

Source from the content-addressed store, hash-verified

371
372/* Render a value to text. */
373static char *print_value(cJSON *item,int depth,int fmt,printbuffer *p)
374{
375 char *out=0;
376 if (!item) return 0;
377 if (p)
378 {
379 switch ((item->type)&255)
380 {
381 case cJSON_NULL: {out=ensure(p,5); if (out) strcpy(out,"null"); break;}
382 case cJSON_False: {out=ensure(p,6); if (out) strcpy(out,"false"); break;}
383 case cJSON_True: {out=ensure(p,5); if (out) strcpy(out,"true"); break;}
384 case cJSON_Number: out=print_number(item,p);break;
385 case cJSON_String: out=print_string(item,p);break;
386 case cJSON_Array: out=print_array(item,depth,fmt,p);break;
387 case cJSON_Object: out=print_object(item,depth,fmt,p);break;
388 }
389 }
390 else
391 {
392 switch ((item->type)&255)
393 {
394 case cJSON_NULL: out=cJSON_strdup("null"); break;
395 case cJSON_False: out=cJSON_strdup("false");break;
396 case cJSON_True: out=cJSON_strdup("true"); break;
397 case cJSON_Number: out=print_number(item,0);break;
398 case cJSON_String: out=print_string(item,0);break;
399 case cJSON_Array: out=print_array(item,depth,fmt,0);break;
400 case cJSON_Object: out=print_object(item,depth,fmt,0);break;
401 }
402 }
403 return out;
404}
405
406/* Build an array from input text. */
407static const char *parse_array(cJSON *item,const char *value)

Callers 5

cJSON_PrintFunction · 0.85
cJSON_PrintUnformattedFunction · 0.85
cJSON_PrintBufferedFunction · 0.85
print_arrayFunction · 0.85
print_objectFunction · 0.85

Calls 6

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

Tested by

no test coverage detected