Move the json entities specific functions to json_entities
This commit is contained in:
@@ -109,3 +109,40 @@ void print_json(const jentity_t *entity, u32 indent) {
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
jcoll_t *get_collection_from_entity(const jentity_t *entity) {
|
||||
return entity->type == JENTITY_SINGLE ? entity->value.collection
|
||||
: entity->pair.value.collection;
|
||||
}
|
||||
|
||||
jentity_t *create_new_single_entity(const jval_t value, jentity_t *parent) {
|
||||
jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t));
|
||||
|
||||
if (!entity) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
entity->type = JENTITY_SINGLE;
|
||||
entity->value = value;
|
||||
entity->parent = parent;
|
||||
entity->next = NULL;
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
jentity_t *create_new_pair_entity(dstr_t *key, const jval_t value,
|
||||
jentity_t *parent) {
|
||||
jentity_t *entity = (jentity_t *)malloc(sizeof(jentity_t));
|
||||
|
||||
if (!entity) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
entity->type = JENTITY_PAIR;
|
||||
entity->pair.key = key;
|
||||
entity->pair.value = value;
|
||||
entity->parent = parent;
|
||||
entity->next = NULL;
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
Reference in New Issue
Block a user