(my)TinyLibC 0.0.1
little tiny pretty lib c
Loading...
Searching...
No Matches
tlcjson.h File Reference
#include "tlcllists.h"
#include "tlcdico.h"

Go to the source code of this file.

Data Structures

struct  any_t
 
union  any_t::value_s
 
struct  json_t
 

Typedefs

typedef enum any_type_e any_type_t
 

Enumerations

enum  json_status_err_e { JS_OK = 0 , JS_ERR_PATH = 1 , JS_ERR_MALLOC = 2 , JS_ERR_INPUT = 3 }
 
enum  any_type_e {
  STR = 0 , INT = 1 , FLOAT = 2 , ARRAY = 3 ,
  DICT = 4
}
 

Functions

any_t * parse_json_file (char const path[])
 parse a json file to any_t
 
any_t * parse_json_str (char const *str)
 parse a char * to any_t
 
int prety_print (any_t *any, int fd)
 print any_t to the file descriptor
 
any_t * get_from_any (any_t *any, char const *format,...)
 get unlimited nested data
 
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)
 
enum json_status_err_e write_json (any_t *any, char const *path)
 write any_t to a json file
 
void destroy_any (void *data)
 destroy any
 
char ** get_any_string_array (any_t *array)
 parse any_t to a char **
 
int * get_any_int_array (any_t *array)
 parse any_t to a int *
 
float * get_any_float_array (any_t *array)
 parse any_t to a float *
 
any_t * create_empty_json (void)
 create an empty any (useful to build a json)
 
any_t * creator_add_any (any_t *root, const char *key, any_t *any)
 add an any_t to the any dico
 
any_t * creator_add_int (any_t *root, const char *key, int number)
 add a number to the any dico
 
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
 

Typedef Documentation

◆ any_type_t

typedef enum any_type_e any_type_t

Definition at line 28 of file tlcjson.h.

Enumeration Type Documentation

◆ any_type_e

enum any_type_e
Enumerator
STR 
INT 
FLOAT 
ARRAY 
DICT 

Definition at line 21 of file tlcjson.h.

21 {
22 STR = 0,
23 INT = 1,
24 FLOAT = 2,
25 ARRAY = 3,
26 DICT = 4
27};
@ 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

◆ json_status_err_e

Enumerator
JS_OK 
JS_ERR_PATH 
JS_ERR_MALLOC 
JS_ERR_INPUT 

Definition at line 14 of file tlcjson.h.

14 {
15 JS_OK = 0,
16 JS_ERR_PATH = 1,
17 JS_ERR_MALLOC = 2,
18 JS_ERR_INPUT = 3
19};
@ 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

Function Documentation

◆ create_empty_json()

any_t * create_empty_json ( void  )

create an empty any (useful to build a json)

Returns
NULL if error; any_t * otherwise

◆ creator_add_any()

any_t * creator_add_any ( any_t *  root,
const char *  key,
any_t *  any 
)

add an any_t to the any dico

Parameters
rootthe root of the dico
keythe key
anythe any (take ownership of this parameter)
Returns
the root

◆ creator_add_float()

any_t * creator_add_float ( any_t *  root,
const char *  key,
float  number 
)

add a number to the any dico

Parameters
rootthe root of the dico
keythe key
numberthe number
Returns
the root

◆ creator_add_int()

any_t * creator_add_int ( any_t *  root,
const char *  key,
int  number 
)

add a number to the any dico

Parameters
rootthe root of the dico
keythe key
numberthe number
Returns
the root

◆ creator_add_string()

any_t * creator_add_string ( any_t *  root,
const char *  key,
const char *  string 
)

add a string to the any dico

Parameters
rootthe root of the dico
keythe key
stringthe string
Returns
the root

◆ destroy_any()

void destroy_any ( void *  data)

destroy any

Parameters
dataany_t to destroy

◆ dico_t_get_any()

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)

Parameters
dicodico in which the key are
keykey to represent the value
Returns
{ NULL : dico or key is NULL, NULL : the key don't exists any_t *: the value asked }

◆ get_any_float_array()

float * get_any_float_array ( any_t *  array)

parse any_t to a float *

Parameters
arrayany_t in which the array float is
Returns
{ NULL : array is NULL, NULL : array contains other than float, float *: the values asked (array of float) }

◆ get_any_int_array()

int * get_any_int_array ( any_t *  array)

parse any_t to a int *

Parameters
arrayany_t in which the array int is
Returns
{ NULL : array is NULL, NULL : array contains other than int int *: the values asked (array of int) }

◆ get_any_string_array()

char ** get_any_string_array ( any_t *  array)

parse any_t to a char **

Parameters
arrayany_t in which the array of char * is
Returns
{ NULL : array is NULL, NULL : array contains other than char *, char **: the values asked (array of char *) }

◆ get_from_any()

any_t * get_from_any ( any_t *  any,
char const *  format,
  ... 
)

get unlimited nested data

to get value of a dico : "d", "key" to get specific index array : "a", 2 you can mix the two (any, "da", "key", 2)

Parameters
anyany in wich the values are
formatformat to use
...unlimited arguments
Returns
{ NULL : any or format is NULL, NULL : the value don't exists, any_t *: the value asked }

◆ parse_json_file()

any_t * parse_json_file ( char const  path[])

parse a json file to any_t

Parameters
pathpath to the json file
Returns
{ NULL : path is NULL, NULL : path is bad, NULL : malloc failed, any_t *: the file has been parsed }

◆ parse_json_str()

any_t * parse_json_str ( char const *  str)

parse a char * to any_t

Parameters
strchar * to parse
Returns
{ NULL : str is NULL, NULL : malloc failed, any_t *: the char * has been parsed }

◆ prety_print()

int prety_print ( any_t *  any,
int  fd 
)

print any_t to the file descriptor

Parameters
anythe any_t to print
fdfiledescriptor to use
Returns
{ int : number of char writed }

◆ write_json()

enum json_status_err_e write_json ( any_t *  any,
char const *  path 
)

write any_t to a json file

Parameters
anyany to write
pathpath to a file that will be override
Returns
status under the form of the enum