MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / print_value

Function print_value

lib/cJSON.c:1060–1166  ·  view source on GitHub ↗

Render a value to text. */

Source from the content-addressed store, hash-verified

1058
1059/* Render a value to text. */
1060static unsigned char *print_value(const cJSON *item, size_t depth, cjbool fmt, printbuffer *p)
1061{
1062 unsigned char *out = NULL;
1063
1064 if (!item)
1065 {
1066 return NULL;
1067 }
1068 if (p)
1069 {
1070 switch ((item->type) & 0xFF)
1071 {
1072 case cJSON_NULL:
1073 out = ensure(p, 5);
1074 if (out)
1075 {
1076 strcpy((char*)out, "null");
1077 }
1078 break;
1079 case cJSON_False:
1080 out = ensure(p, 6);
1081 if (out)
1082 {
1083 strcpy((char*)out, "false");
1084 }
1085 break;
1086 case cJSON_True:
1087 out = ensure(p, 5);
1088 if (out)
1089 {
1090 strcpy((char*)out, "true");
1091 }
1092 break;
1093 case cJSON_Number:
1094 out = print_number(item, p);
1095 break;
1096 case cJSON_Raw:
1097 {
1098 size_t raw_length = 0;
1099 if (item->valuestring == NULL)
1100 {
1101 if (!p->noalloc)
1102 {
1103 cJSON_free(p->buffer);
1104 }
1105 out = NULL;
1106 break;
1107 }
1108
1109 raw_length = strlen(item->valuestring) + sizeof('\0');
1110 out = ensure(p, raw_length);
1111 if (out)
1112 {
1113 memcpy(out, item->valuestring, raw_length);
1114 }
1115 break;
1116 }
1117 case cJSON_String:

Callers 7

cJSON_PrintFunction · 0.70
cJSON_PrintUnformattedFunction · 0.70
cJSON_PrintBufferedFunction · 0.70
cJSON_PrintPreallocatedFunction · 0.70
cJSON_PrintFlushedFunction · 0.70
print_arrayFunction · 0.70
print_objectFunction · 0.70

Calls 6

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

Tested by

no test coverage detected