json_encoder.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * File: json_parser.c
  3. * Author: Arthur Brandao
  4. *
  5. * Created on 29 octobre 2018
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "json.h"
  10. /* --- Fonctions privée --- */
  11. void add_node(JsonEncoder* this, char* key, char* val){
  12. //Création node
  13. JsonNode* node;
  14. node = malloc(sizeof(JsonNode));
  15. //Allocation node
  16. node->key = malloc(strlen(key) * sizeof(char));
  17. node->val = malloc(strlen(val) * sizeof(char));
  18. //Initialisation node
  19. strcpy(node->key, key);
  20. strcpy(node->val, val);
  21. //Si 1er node
  22. if(this->head == NULL){
  23. this->head = node;
  24. node->prev = NULL;
  25. } else {
  26. node->prev = this->tail;
  27. node->prev->next = node;
  28. }
  29. this->tail = node;
  30. node->next = NULL;
  31. }
  32. void delete_node(JsonNode* node){
  33. free(node->key);
  34. free(node->val);
  35. free(node);
  36. }
  37. /* --- Fonctions publique --- */
  38. void ini_encoder(JsonEncoder* this){
  39. this->head = NULL;
  40. this->tail = NULL;
  41. this->length = 0;
  42. }
  43. int add_value(JsonEncoder* this, char* key, char* val){
  44. }
  45. int add_number(JsonEncoder*, double){
  46. }
  47. int add_integer(JsonEncoder*, int){
  48. }
  49. int add_boolean(JsonEncoder*, boolean){
  50. }
  51. int add_array(JsonEncoder*, char*){
  52. }
  53. int add_object(JsonEncoder*, JsonEncoder){
  54. }
  55. char* json_encode(JsonEncoder*){
  56. }
  57. void clean_json_encoder(JsonEncoder* this){
  58. }