moved functions code to separate files

This commit is contained in:
2025-11-26 16:26:01 +05:00
parent 52870920c1
commit 048542d079
28 changed files with 1594 additions and 1511 deletions

42
src/TomlArray.c Normal file
View File

@@ -0,0 +1,42 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "toml_internal.h"
TomlArray* TomlArray_new(void)
{
TomlArray* array = malloc(sizeof(TomlArray));
array->elements = NULL;
array->len = 0;
array->_capacity = 0;
return array;
}
void TomlArray_free(TomlArray* self)
{
if (self == NULL)
return;
for (u64 i = 0; i < self->len; i++) {
TomlValue_destroy(&self->elements[i]);
}
free(self->elements);
free(self);
}
void TomlArray_expand_if_necessary(TomlArray* self)
{
if (self->len + 1 > self->_capacity) {
u64 new_capacity = self->_capacity > 0 ? self->_capacity * 2 : 8;
void* p = realloc(self->elements, sizeof(TomlValue) * new_capacity);
self->elements = p;
self->_capacity = new_capacity;
}
}
void TomlArray_append(TomlArray* self, TomlValue value)
{
TomlArray_expand_if_necessary(self);
self->elements[self->len++] = value;
}