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

View File

@@ -0,0 +1,87 @@
/* 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"
TomlTable* toml_walk_table_path(TomlParser* parser, TomlTable* table,
TomlArray* key_path, i32 is_array, i32 create_if_not_exist)
{
TomlTable* real_table = table;
if (is_array) {
u64 i = 0;
for (; i < key_path->len - 1; i++) {
str part = key_path->elements[i].value.s;
TomlValue* t = TomlTable_get(real_table, part);
if (t == NULL) {
if (create_if_not_exist) {
TomlValue new_table_value = TomlValue_new_table();
TomlTable_set(real_table, part, new_table_value);
real_table = new_table_value.value.table;
} else {
real_table = NULL;
break;
}
} else {
real_table = t->value.table;
}
}
str part = key_path->elements[i].value.s;
TomlValue* t = TomlTable_get(real_table, part);
if (t == NULL) {
if (create_if_not_exist) {
TomlValue array_value = TomlValue_new_array();
TomlValue new_table_value = TomlValue_new_table();
TomlArray_append(array_value.value.array, new_table_value);
TomlTable_set(real_table, part, array_value);
real_table = new_table_value.value.table;
} else {
real_table = NULL;
}
} else {
if (t->type != TLIBTOML_ARRAY) {
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX, "%s:%d:%d: this key was not an array",
parser->filename, parser->lineno, parser->colno);
goto error;
}
TomlValue new_table_value = TomlValue_new_table();
TomlArray_append(t->value.array, new_table_value);
real_table = new_table_value.value.table;
}
} else {
for (u64 i = 0; i < key_path->len; i++) {
str part = key_path->elements[i].value.s;
TomlValue* t = TomlTable_get(real_table, part);
if (t == NULL) {
if (create_if_not_exist) {
TomlValue new_table_value = TomlValue_new_table();
TomlTable_set(real_table, part, new_table_value);
real_table = new_table_value.value.table;
} else {
real_table = NULL;
break;
}
} else {
if (t->type == TLIBTOML_ARRAY) {
real_table = t->value.array->elements[t->value.array->len - 1].value.table;
} else if (t->type == TLIBTOML_TABLE) {
real_table = t->value.table;
}
}
}
}
goto end;
error:
real_table = NULL;
//TODO: error handling
assert(false && "TODO error handling");
end:
return real_table;
}