From 03a2d9c70e87dc180fa7311b6afda36483fc4ba9 Mon Sep 17 00:00:00 2001 From: hellerve Date: Fri, 23 Jul 2021 17:24:36 +0200 Subject: [PATCH] string printing: simplify --- cfg.h | 26 +------------------------- example.cfg | 3 ++- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/cfg.h b/cfg.h index 843e0fb..d30be09 100644 --- a/cfg.h +++ b/cfg.h @@ -102,29 +102,6 @@ bool string_compare(string* a, string* b) { return strncmp(a->str, b->str, a->len) == 0; } -ssize_t string_count_escaped_chars(string* s) { - size_t i; - ssize_t res = 0; - for (i = 0; i < s->len; i++) if (s->str[i] == '"' || s->str[i] == '\\') res++; - return res; -} - -string string_quote(string* replace) { - size_t i = 0; - ssize_t quotes = string_count_escaped_chars(replace); - string res = new_string_sized(replace->len+quotes); - res.len = res.cap; - - quotes = 0; - for (i = 0; i < replace->len; i++) { - if (replace->str[i] == '"') res.str[i+(quotes++)] = '\\'; - else if (replace->str[i] == '\\') res.str[i+(quotes++)] = '\\'; - res.str[i+quotes] = replace->str[i]; - } - - return res; -} - ssize_t string_find_whitespace(string* s) { ssize_t i; char c; @@ -413,8 +390,7 @@ string config_value_str(config_value* c, size_t indent) { return res; case config_value_string: string_cappend(&res, "\""); - sub = string_quote(&c->s); - string_append(&res, &sub); + string_append(&res, &c->s); string_cappend(&res, "\""); break; case config_value_number: diff --git a/example.cfg b/example.cfg index ec21c60..85f90a9 100644 --- a/example.cfg +++ b/example.cfg @@ -4,7 +4,8 @@ hi name 1 val "hi" list - - "value" + - "value + \"multi" - -1 - - "this"