replaced TomlTable with HashMap
This commit is contained in:
23
tests/main.c
23
tests/main.c
@@ -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("}");
|
||||
|
||||
Reference in New Issue
Block a user