JST: JSON tools  1.0.0
JSON tools dynamic library for reading, manipulating and writing JSON tree
JST_delete.c
Go to the documentation of this file.
1 #include "jstools.h"
2 
3 #include <stdlib.h>
4 
6  if( pair == NULL ) {
8  }
9  JST_Error error = JST_delete_element( &(pair->element));
10  free( pair->name );
11  free( pair );
12  return error;
13 }
14 
16  if( object == NULL ) {
17  return JST_ERR_NULL_ARGUMENT;
18  }
19  JST_Error error = JST_ERR_NONE;
20  for( unsigned i = 0; ( error == JST_ERR_NONE )&&( i < object->count ); ++i ) {
21  error = JST_delete_pair( object->items[i] );
22  }
23  free( object->items );
24  object->parent = NULL;
25  object->count = 0;
26  object->first = NULL;
27  object->items = NULL;
28  return error;
29 }
30 
32  if( item == NULL ) {
33  return JST_ERR_NULL_ARGUMENT;
34  }
35  JST_Error error = JST_delete_element( &(item->element));
36  free( item );
37  return error;
38 }
39 
41  if( array == NULL ) {
42  return JST_ERR_NULL_ARGUMENT;
43  }
44  JST_Error error = JST_ERR_NONE;
45  for( unsigned i = 0; ( error == JST_ERR_NONE )&&( i < array->count ); ++i ) {
46  error = JST_delete_array_item( array->items[i] );
47  }
48  free( array->items );
49  array->parent = NULL;
50  array->count = 0;
51  array->items = NULL;
52  return error;
53 }
54 
56  if( element == NULL ) {
57  return JST_ERR_NULL_ARGUMENT;
58  }
59  switch( element->type ) {
60  case JST_OBJECT: JST_delete_object( &(element->value.object)); break;
61  case JST_ARRAY : JST_delete_array( &(element->value.array)); break;
62  case JST_STRING: free( element->value.string ); break;
63  default: break;
64  }
65  element->type = JST_NULL;
66  element->value.string = NULL;
67  return JST_ERR_NONE;
68 }
struct JST_Pair_ ** items
Array of JST_Pair, ordered by JST_Pair.name to ease search with bsearch()
Definition: jstools.h:25
char * name
This property&#39;s name.
Definition: jstools.h:96
A object attribute item has a parent and is a named-typed-value pair.
Definition: jstools.h:93
A JSON array.
Definition: jstools.h:10
JST_Element element
Definition: jstools.h:85
An array item has a parent and a typed value.
Definition: jstools.h:83
char * string
Definition: jstools.h:46
A JSON object, a sorted set of named-value pairs.
Definition: jstools.h:24
JST_Object object
Definition: jstools.h:41
JST_Value value
Definition: jstools.h:72
JST_Error JST_delete_array(JST_Array *array)
Definition: JST_delete.c:40
JST_Error
When things goes wrong, an error information is given.
Definition: jstools.h:108
An element is a typed value.
Definition: jstools.h:70
JST_Array array
Definition: jstools.h:42
JST_Error JST_delete_pair(JST_Pair *pair)
Definition: JST_delete.c:5
JST_Error JST_delete_array_item(JST_ArrayItem *item)
Definition: JST_delete.c:31
Function misused.
Definition: jstools.h:110
struct JST_ArrayItem_ ** items
Array of JST_ArrayItem.
Definition: jstools.h:11
JST_Error JST_delete_object(JST_Object *object)
Definition: JST_delete.c:15
JST_Error JST_delete_element(JST_Element *element)
Definition: JST_delete.c:55
unsigned count
Cardinality of the previous array.
Definition: jstools.h:12
JST_ValueType type
Definition: jstools.h:71
struct JST_Element_ * parent
of type JST_ArrayItem or JST_Pair, case selector is parent->type
Definition: jstools.h:13
JST_Element element
The value associated with the name.
Definition: jstools.h:95