From 81602f6c59ef8b9595f8fc6ad5065a22ab536858 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 13 Mar 2025 11:51:38 -0400 Subject: Encapsulate writer indentation code This makes write_sep() responsible for all indentation changes (except resetting it to zero), removing some spooky action at a distance around object comma indentation. --- src/writer.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/writer.c') diff --git a/src/writer.c b/src/writer.c index 6a5acaf0..1c96ca13 100644 --- a/src/writer.c +++ b/src/writer.c @@ -542,10 +542,13 @@ write_sep(SerdWriter* const writer, const Sep sep) : 0); } - // If this is the first comma, bump the increment for the following object + // Adjust indentation for object comma if necessary if (sep == SEP_END_O && !writer->context.comma_indented) { ++writer->indent; writer->context.comma_indented = true; + } else if (sep == SEP_END_P && writer->context.comma_indented) { + --writer->indent; + writer->context.comma_indented = false; } // Write newline or space before separator if necessary @@ -995,11 +998,6 @@ serd_writer_write_statement(SerdWriter* const writer, } else { // Elide S (write P and O) - if (writer->context.comma_indented) { - --writer->indent; - writer->context.comma_indented = false; - } - const bool first = !writer->context.predicate.type; TRY(st, write_sep(writer, first ? SEP_S_P : SEP_END_P)); TRY(st, write_pred(writer, flags, predicate)); -- cgit v1.2.1