replaced TomlTable with HashMap

This commit is contained in:
2025-11-10 10:31:47 +05:00
parent a33505ffe4
commit c49a8cb1e5
3 changed files with 232 additions and 311 deletions

View File

@@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <inttypes.h>
#include <assert.h>
#include "tlibtoml/toml.h"
#ifndef PROJECT_SOURCE_DIR
@@ -19,7 +20,7 @@ void print_array(const TomlArray *array)
if (i > 0) {
printf(", ");
}
print_value(array->elements[i]);
print_value(&array->elements[i]);
}
printf("]");
}
@@ -27,6 +28,9 @@ void print_array(const TomlArray *array)
void print_value(const TomlValue* value)
{
switch (value->type) {
default:
assert(false && "invalid type");
break;
case TOML_TABLE:
print_table(value->value.table);
break;
@@ -51,7 +55,7 @@ void print_value(const TomlValue* value)
}
}
void print_keyval(const TomlKeyValue *keyval)
void print_keyval(HashMapKeyValue* keyval)
{
printf("\"%s\": ", keyval->key.data);
print_value(keyval->value);
@@ -59,19 +63,16 @@ void print_keyval(const TomlKeyValue *keyval)
void print_table(const TomlTable* table)
{
TomlTableIter it = toml_table_iter_new((TomlTable*)table);
HashMapIter it = HashMapIter_create(table);
printf("{");
u64 i = 0;
while (toml_table_iter_has_next(&it)) {
TomlKeyValue *keyval = toml_table_iter_get(&it);
if (i > 0) {
HashMapKeyValue keyval;
while (HashMapIter_moveNext(&it)) {
assert(HashMapIter_getCurrent(&it, &keyval));
if (i > 0)
printf(", ");
}
print_keyval(keyval);
toml_table_iter_next(&it);
print_keyval(&keyval);
i++;
}
printf("}");