diff options
author | Freya Murphy <freya@freyacat.org> | 2023-12-16 11:47:59 -0500 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2023-12-16 11:47:59 -0500 |
commit | 85ba301f52b1c7e1ad928803b14b6c70776f2235 (patch) | |
tree | 28902147b9bf6c393497e21b0cb21c8b957aa3e2 /src/json/print.c | |
parent | fix hang on incomplete json ident (diff) | |
download | nbtvis-85ba301f52b1c7e1ad928803b14b6c70776f2235.tar.gz nbtvis-85ba301f52b1c7e1ad928803b14b6c70776f2235.tar.bz2 nbtvis-85ba301f52b1c7e1ad928803b14b6c70776f2235.zip |
use hashmap for compound tag
Diffstat (limited to '')
-rw-r--r-- | src/json/print.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/json/print.c b/src/json/print.c index 97ccce8..9f2931f 100644 --- a/src/json/print.c +++ b/src/json/print.c @@ -68,7 +68,7 @@ static bool json_print_long_array(const tagdata_t *data, const stream_t *stream) } static bool json_print_string(const tagdata_t *data, const stream_t *stream) { - if (data->string.size > 1) { + if (data->string.size > 0) { if (printi(stream, 0, "\"%.*s\"", data->string.size, data->string.data) == false) return false; } else { @@ -81,10 +81,14 @@ static bool json_print_string(const tagdata_t *data, const stream_t *stream) { static bool json_print_compound(const tagdata_t *data, const stream_t *stream, int depth) { if (printi(stream, 0, "{\n") == false) return false; - for (int32_t i = 0; i < data->compound.size; i++) { - if (i != 0 && printi(stream, 0, ",\n") == false) + bool first = true; + for (uint32_t i = 0; i < data->compound.capacity; i++) { + if (data->compound.entries[i].name == NULL) + continue; + if (!first && printi(stream, 0, ",\n") == false) return false; - if (json_print_impl(&data->compound.tags[i], stream, depth + 1) == false) + first = false; + if (json_print_impl(&data->compound.entries[i], stream, depth + 1) == false) return false; } if (printi(stream, 0, "\n") == false || printi(stream, depth, "}") == false) |