Move the json entities specific functions to json_entities

This commit is contained in:
2023-07-01 15:04:59 +01:00
parent 99f5c5bfe5
commit ff110ea6e2
3 changed files with 51 additions and 10 deletions

View File

@@ -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;
}