(my)TinyLibC 0.0.1
little tiny pretty lib c
Loading...
Searching...
No Matches
tlcjson.h
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2023
3** (my) Tiny Lib C
4** File description:
5** json header
6*/
7
8#ifndef TLS_JSONC_H_
9 #define TLS_JSONC_H_
10
11 #include "tlcllists.h"
12 #include "tlcdico.h"
13
15 JS_OK = 0,
18 JS_ERR_INPUT = 3
19};
20
22 STR = 0,
23 INT = 1,
24 FLOAT = 2,
25 ARRAY = 3,
26 DICT = 4
27};
29
30struct any_s {
32 union value_s {
33 char *str;
34 int i;
35 float f;
36 list_t *array;
37 dico_t *dict;
38 char c;
40};
41typedef struct any_s any_t;
42
43struct json_s {
44 any_t *dico;
46};
47typedef struct json_s json_t;
48
49// ----------------------------------------------------------------------------
50
63any_t *parse_json_file(char const path[]);
64
76any_t *parse_json_str(char const *str);
77
88int prety_print(any_t *any, int fd);
89
108any_t *get_from_any(any_t *any, char const *format, ...);
109
122any_t *dico_t_get_any(dico_t *dico, char const *key);
123
132enum json_status_err_e write_json(any_t *any, char const *path);
133
139void destroy_any(void *data);
140
152char **get_any_string_array(any_t *array);
153
165int *get_any_int_array(any_t *array);
166
178float *get_any_float_array(any_t *array);
179
185any_t *create_empty_json(void);
186
196any_t *creator_add_any(any_t *root, const char *key, any_t *any);
197
207any_t *creator_add_int(any_t *root, const char *key, int number);
208
218any_t *creator_add_float(any_t *root, const char *key, float number);
219
229any_t *creator_add_string(any_t *root, const char *key, const char *string);
230
231#endif
union any_s::value_s value
any_type_t type
Definition tlcjson.h:31
int nb_keys
Definition tlcjson.h:45
any_t * dico
Definition tlcjson.h:44
any_t * creator_add_int(any_t *root, const char *key, int number)
add a number to the any dico
any_t * parse_json_str(char const *str)
parse a char * to any_t
int * get_any_int_array(any_t *array)
parse any_t to a int *
any_t * dico_t_get_any(dico_t *dico, char const *key)
get any_t from a dico_t (cast void * of dico_t value)
any_t * creator_add_float(any_t *root, const char *key, float number)
add a number to the any dico
any_t * creator_add_string(any_t *root, const char *key, const char *string)
add a string to the any dico
enum any_type_e any_type_t
Definition tlcjson.h:28
float * get_any_float_array(any_t *array)
parse any_t to a float *
any_t * get_from_any(any_t *any, char const *format,...)
get unlimited nested data
any_t * creator_add_any(any_t *root, const char *key, any_t *any)
add an any_t to the any dico
enum json_status_err_e write_json(any_t *any, char const *path)
write any_t to a json file
char ** get_any_string_array(any_t *array)
parse any_t to a char **
json_status_err_e
Definition tlcjson.h:14
@ JS_ERR_MALLOC
Definition tlcjson.h:17
@ JS_OK
Definition tlcjson.h:15
@ JS_ERR_PATH
Definition tlcjson.h:16
@ JS_ERR_INPUT
Definition tlcjson.h:18
void destroy_any(void *data)
destroy any
any_type_e
Definition tlcjson.h:21
@ DICT
Definition tlcjson.h:26
@ ARRAY
Definition tlcjson.h:25
@ FLOAT
Definition tlcjson.h:24
@ STR
Definition tlcjson.h:22
@ INT
Definition tlcjson.h:23
any_t * create_empty_json(void)
create an empty any (useful to build a json)
any_t * parse_json_file(char const path[])
parse a json file to any_t
int prety_print(any_t *any, int fd)
print any_t to the file descriptor
char * str
Definition tlcjson.h:33
dico_t * dict
Definition tlcjson.h:37
list_t * array
Definition tlcjson.h:36