Move the json entities specific functions to json_entities
This commit is contained in:
parent
99f5c5bfe5
commit
ff110ea6e2
@ -170,12 +170,12 @@
|
||||
"-x",
|
||||
"c",
|
||||
"-o",
|
||||
"/tmp/main-9b4cff.o",
|
||||
"/tmp/main-6b800d.o",
|
||||
"src/main.c"
|
||||
],
|
||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/main.c",
|
||||
"output": "/tmp/main-9b4cff.o"
|
||||
"output": "/tmp/main-6b800d.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
@ -243,12 +243,12 @@
|
||||
"-x",
|
||||
"c",
|
||||
"-o",
|
||||
"/tmp/dstring-a07695.o",
|
||||
"/tmp/dstring-08596e.o",
|
||||
"src/dstring/dstring.c"
|
||||
],
|
||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/dstring/dstring.c",
|
||||
"output": "/tmp/dstring-a07695.o"
|
||||
"output": "/tmp/dstring-08596e.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
@ -316,12 +316,12 @@
|
||||
"-x",
|
||||
"c",
|
||||
"-o",
|
||||
"/tmp/json_entities-bcc119.o",
|
||||
"/tmp/json_entities-a48410.o",
|
||||
"src/json_entities/json_entities.c"
|
||||
],
|
||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/json_entities/json_entities.c",
|
||||
"output": "/tmp/json_entities-bcc119.o"
|
||||
"output": "/tmp/json_entities-a48410.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
@ -389,12 +389,12 @@
|
||||
"-x",
|
||||
"c",
|
||||
"-o",
|
||||
"/tmp/lexer-2e4754.o",
|
||||
"/tmp/lexer-174a98.o",
|
||||
"src/lexer/lexer.c"
|
||||
],
|
||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/lexer/lexer.c",
|
||||
"output": "/tmp/lexer-2e4754.o"
|
||||
"output": "/tmp/lexer-174a98.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
@ -462,11 +462,11 @@
|
||||
"-x",
|
||||
"c",
|
||||
"-o",
|
||||
"/tmp/parser-2d2a43.o",
|
||||
"/tmp/parser-baae30.o",
|
||||
"src/parser/parser.c"
|
||||
],
|
||||
"directory": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json",
|
||||
"file": "/mnt/3A5CDF785CDF2CFF/Users/abdoo/dev/say_it_in_json/src/parser/parser.c",
|
||||
"output": "/tmp/parser-2d2a43.o"
|
||||
"output": "/tmp/parser-baae30.o"
|
||||
}
|
||||
]
|
||||
|
@ -65,5 +65,9 @@ struct json_collection {
|
||||
};
|
||||
|
||||
void print_json(const jentity_t *entity, u32 indent);
|
||||
jcoll_t *get_collection_from_entity(const jentity_t *entity);
|
||||
jentity_t *create_new_single_entity(const jval_t value, jentity_t *parent);
|
||||
jentity_t *create_new_pair_entity(dstr_t *key, const jval_t value,
|
||||
jentity_t *parent);
|
||||
|
||||
#endif // !JSON_ENTITIES_H
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user