1234567891011121314151617181920212223242526272829303132333435363738 |
- /*
- * File: json.c
- * Author: Arthur Brandao
- *
- * Created on 24 novembre 2018
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "json.h"
- /* --- Fonctions publiques --- */
- void add_json_node(JsonEncoder* this, char* str){
- //Création node
- JsonNode* node;
- node = malloc(sizeof(JsonNode));
- //Allocation node
- int length = strlen(str) + 1;
- node->str = malloc(length * sizeof(char));
- memset(node->str, 0, length);
- strncpy(node->str, str, length - 1);
- //Si 1er node
- if(this->head == NULL){
- this->head = node;
- node->prev = NULL;
- } else {
- node->prev = this->tail;
- node->prev->next = node;
- }
- this->tail = node;
- node->next = NULL;
- }
- void delete_json_node(JsonNode* node){
- free(node->str);
- }
|