MCPcopy Index your code
hub / github.com/antirez/botlib / add_item_to_object

Function add_item_to_object

cJSON.c:2007–2042  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2005
2006
2007static 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)
2008{
2009 char *new_key = NULL;
2010 int new_type = cJSON_Invalid;
2011
2012 if ((object == NULL) || (string == NULL) || (item == NULL) || (object == item))
2013 {
2014 return false;
2015 }
2016
2017 if (constant_key)
2018 {
2019 new_key = (char*)cast_away_const(string);
2020 new_type = item->type | cJSON_StringIsConst;
2021 }
2022 else
2023 {
2024 new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks);
2025 if (new_key == NULL)
2026 {
2027 return false;
2028 }
2029
2030 new_type = item->type & ~cJSON_StringIsConst;
2031 }
2032
2033 if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
2034 {
2035 hooks->deallocate(item->string);
2036 }
2037
2038 item->string = new_key;
2039 item->type = new_type;
2040
2041 return add_item_to_array(object, item);
2042}
2043
2044CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
2045{

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