diff options
-rw-r--r-- | common.c | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -1274,6 +1274,26 @@ config_item_write_string (struct str *output, const struct str *s) } static void +config_item_write_object + (struct config_writer *self, struct config_item_ *value) +{ + char indent[self->indent + 1]; + memset (indent, '\t', self->indent); + indent[self->indent] = 0; + + str_append_c (self->output, '{'); + if (value->value.object.len) + { + self->indent++; + str_append_c (self->output, '\n'); + config_item_write_object_innards (self, value); + self->indent--; + str_append (self->output, indent); + } + str_append_c (self->output, '}'); +} + +static void config_item_write_value (struct config_writer *self, struct config_item_ *value) { switch (value->type) @@ -1292,20 +1312,8 @@ config_item_write_value (struct config_writer *self, struct config_item_ *value) config_item_write_string (self->output, &value->value.string); break; case CONFIG_ITEM_OBJECT: - { - char indent[self->indent + 1]; - memset (indent, '\t', self->indent); - indent[self->indent] = 0; - - str_append (self->output, "{\n"); - - self->indent++; - config_item_write_object_innards (self, value); - self->indent--; - - str_append_printf (self->output, "%s}", indent); + config_item_write_object (self, value); break; - } default: hard_assert (!"invalid item type"); } |