aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2025-03-13 11:51:38 -0400
committerDavid Robillard <d@drobilla.net>2025-03-16 20:26:27 -0400
commit81602f6c59ef8b9595f8fc6ad5065a22ab536858 (patch)
tree1e889b7ddedb20344eeb87c626f264f2f2bac58c /src/writer.c
parent653476c24f9ab53e846426015f05a94b69d70e30 (diff)
downloadserd-81602f6c59ef8b9595f8fc6ad5065a22ab536858.tar.gz
serd-81602f6c59ef8b9595f8fc6ad5065a22ab536858.tar.bz2
serd-81602f6c59ef8b9595f8fc6ad5065a22ab536858.zip
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.
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c10
1 files changed, 4 insertions, 6 deletions
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));