MCPcopy Create free account
hub / github.com/DaveGamble/cJSON / add_item_to_object

Function add_item_to_object

cJSON.c:2067–2102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2065
2066
2067static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key)
2068{
2069 char *new_key = NULL;
2070 int new_type = cJSON_Invalid;
2071
2072 if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item))
2073 {
2074 return false;
2075 }
2076
2077 if (constant_key)
2078 {
2079 new_key = (char*)cast_away_const(string);
2080 new_type = item->type | cJSON_StringIsConst;
2081 }
2082 else
2083 {
2084 new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks);
2085 if (new_key == NULL)
2086 {
2087 return false;
2088 }
2089
2090 new_type = item->type & ~cJSON_StringIsConst;
2091 }
2092
2093 if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
2094 {
2095 hooks->deallocate(item->string);
2096 }
2097
2098 item->string = new_key;
2099 item->type = new_type;
2100
2101 return add_item_to_array(object, item);
2102}
2103
2104CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
2105{

Callers 12

cJSON_AddItemToObjectFunction · 0.85
cJSON_AddItemToObjectCSFunction · 0.85
cJSON_AddNullToObjectFunction · 0.85
cJSON_AddTrueToObjectFunction · 0.85
cJSON_AddFalseToObjectFunction · 0.85
cJSON_AddBoolToObjectFunction · 0.85
cJSON_AddNumberToObjectFunction · 0.85
cJSON_AddStringToObjectFunction · 0.85
cJSON_AddRawToObjectFunction · 0.85
cJSON_AddObjectToObjectFunction · 0.85
cJSON_AddArrayToObjectFunction · 0.85

Calls 3

cast_away_constFunction · 0.85
cJSON_strdupFunction · 0.85
add_item_to_arrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…