runtime: format: only add trailing newline to string if one isn't already present

This commit is contained in:
2026-06-14 19:40:27 +01:00
parent b3440fe231
commit de2a747e36
+13
View File
@@ -28,13 +28,26 @@ static void write_iterable(struct bshell_value_writer *w, const fx_value *value)
fx_iterator_unref(it);
}
static bool string_has_trailing_newline(const char *s)
{
long len = strlen(s);
if (len == 0) {
return false;
}
return s[len - 1] == '\n';
}
static void write_string(struct bshell_value_writer *w, const fx_value *value)
{
const char *str = NULL;
fx_value_get_cstr(value, &str);
fx_stream_write_cstr(w->w_dest, str, NULL);
if (!string_has_trailing_newline(str)) {
fx_stream_write_char(w->w_dest, '\n');
}
}
static void write_value(struct bshell_value_writer *w, const fx_value *value)
{