8#include "../nyx_node_internal.h"
12typedef struct nyx_list_node_s
16 struct nyx_list_node_s *next;
22static void internal_list_clear(
52 internal_list_clear(
object);
59static void internal_list_clear(
nyx_list_t *
object)
63 for(node_t *node = object->head; node != NULL;)
73 nyx_object_free(temp->value);
92 internal_list_clear(
object);
101 for(node_t *prev_node = NULL, *curr_node = object->head; curr_node != NULL; prev_node = curr_node, curr_node = curr_node->next, idx--)
107 if(prev_node == NULL)
109 object->head = curr_node->next;
113 prev_node->next = curr_node->next;
118 nyx_object_free(curr_node->value);
135 if(iter->
head != NULL)
142 *
object = iter->
head->value;
145 iter->
idx += 0x0000000000001;
160 for(node_t *curr_node = object->head; curr_node != NULL; curr_node = curr_node->next, idx--)
164 return curr_node->value;
175bool nyx_list_set(
nyx_list_t *
object,
size_t idx,
void *value)
190 bool modified =
true;
192 for(node_t *curr_node = object->head; curr_node != NULL; curr_node = curr_node->next, idx--)
196 modified = !nyx_object_equal(curr_node->value, value);
198 nyx_object_free(curr_node->value);
200 curr_node->value = value;
215 if(object->head == NULL)
222 object->tail->next = node;
239 for(node_t *node = object->head; node != NULL; node = node->next, result++) { };
250 nyx_string_builder_t *sb = nyx_string_builder_new();
252 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"[");
254 for(node_t *curr_node = object->head; curr_node != NULL; curr_node = curr_node->next)
258 str_t curr_node_val = nyx_object_to_string(curr_node->value);
260 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE, curr_node_val);
266 if(curr_node->next != NULL)
268 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
",");
273 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"]");
275 str_t result = nyx_string_builder_to_string(sb);
277 nyx_string_builder_free(sb);
#define NYX_LOG_FATAL(fmt,...)
Logs a fatal message.
__NYX_NULLABLE__ buff_t nyx_memory_alloc(__NYX_ZEROABLE__ size_t size)
Similar to libc malloc except that a memory overflow causes the node to stop.
__NYX_ZEROABLE__ size_t nyx_memory_free(__NYX_NULLABLE__ buff_t buff)
Similar to libc free except that it returns the amount of memory freed.
#define str_t
Alias for char *.
#define NYX_OBJECT_MAGIC
Magic number for identifying JSON objects.
@ NYX_TYPE_LIST
List object.
Struct describing a JSON list iterator.
struct nyx_list_node_s * head
Next JSON object to visit.
size_t idx
Current zero-based iteration index.
Struct describing a JSON list object.
Struct describing a JSON object.