new xj_array_append

This commit is contained in:
cozis
2022-04-28 13:31:42 +02:00
parent 8fbdd029d4
commit 8ed2ed7404
2 changed files with 42 additions and 0 deletions
+40
View File
@@ -507,6 +507,46 @@ xj_value *xj_value_object(xj_value *head, xj_alloc *alloc, xj_error *error)
return xj_value_object__nocheck(head, count, alloc, error); return xj_value_object__nocheck(head, count, alloc, error);
} }
_Bool xj_array_append(xj_value *array, xj_value *child,
xj_error *error)
{
assert(array != NULL);
if(child != NULL)
{
if(child->key != NULL)
{
xj_report(error, "Array child can't have a key");
return 0;
}
if(child->next != NULL)
{
xj_report(error, "Array child can't be in a list");
return 0;
}
// Find the end of the array
xj_value **tail;
if(array->as_array == NULL)
// The tail is the base node pointer
tail = &array->as_array;
else
{
// Scan the list 'til the end
xj_value *curs = array->as_array;
while(curs->next != NULL)
curs = curs->next;
tail = &curs;
}
*tail = child;
}
return 1;
}
char *xj_strdup(const char *str, int len, xj_alloc *alloc, xj_error *error) char *xj_strdup(const char *str, int len, xj_alloc *alloc, xj_error *error)
{ {
assert(str != NULL); assert(str != NULL);
+2
View File
@@ -60,6 +60,8 @@ xj_value *xj_value_string(const char *str, int len, xj_alloc *alloc, xj_error *e
xj_value *xj_value_array__nocheck(xj_value *head, int count, xj_alloc *alloc, xj_error *error); xj_value *xj_value_array__nocheck(xj_value *head, int count, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_object__nocheck(xj_value *head, int count, xj_alloc *alloc, xj_error *error); xj_value *xj_value_object__nocheck(xj_value *head, int count, xj_alloc *alloc, xj_error *error);
_Bool xj_array_append(xj_value *array, xj_value *child, xj_error *error);
char *xj_strdup(const char *str, int len, xj_alloc *alloc, xj_error *error); char *xj_strdup(const char *str, int len, xj_alloc *alloc, xj_error *error);
xj_value *xj_decode(const char *str, int len, xj_alloc *alloc, xj_error *error); xj_value *xj_decode(const char *str, int len, xj_alloc *alloc, xj_error *error);