aboutsummaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-02 04:02:23 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-02 04:02:23 +0200
commit83e159d9451fce521a04c2bf09bb6abe866c6231 (patch)
tree7e471583bd2e6dd6b4c50d2159cb38afcc3a8fcd /common.c
parentfddcef24f98bea002a7d62d072816cd3517582fa (diff)
downloadxK-83e159d9451fce521a04c2bf09bb6abe866c6231.tar.gz
xK-83e159d9451fce521a04c2bf09bb6abe866c6231.tar.xz
xK-83e159d9451fce521a04c2bf09bb6abe866c6231.zip
config: finish config_item_write() implementation
Diffstat (limited to 'common.c')
-rw-r--r--common.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/common.c b/common.c
index 3dee9a5..67781dc 100644
--- a/common.c
+++ b/common.c
@@ -782,6 +782,24 @@ static void config_item_write_object_innards
(struct config_writer *self, struct config_item_ *object);
static void
+config_item_write_string (struct str *output, const struct str *s)
+{
+ str_append_c (output, '"');
+ for (size_t i = 0; i < s->len; i++)
+ {
+ unsigned char c = s->str[i];
+ if (c == '\n') str_append (output, "\\n");
+ else if (c == '\r') str_append (output, "\\r");
+ else if (c == '\t') str_append (output, "\\t");
+ else if (c == '\\') str_append (output, "\\\\");
+ else if (c == '"') str_append (output, "\\\"");
+ else if (c < 32) str_append_printf (output, "\\x%02x", c);
+ else str_append_c (output, c);
+ }
+ str_append_c (output, '"');
+}
+
+static void
config_item_write_value (struct config_writer *self, struct config_item_ *value)
{
switch (value->type)
@@ -797,7 +815,7 @@ config_item_write_value (struct config_writer *self, struct config_item_ *value)
break;
case CONFIG_ITEM_STRING:
case CONFIG_ITEM_STRING_ARRAY:
- // TODO
+ config_item_write_string (self->output, &value->value.string);
break;
case CONFIG_ITEM_OBJECT:
{