runtime: format: only add trailing newline to string if one isn't already present
This commit is contained in:
@@ -28,12 +28,25 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user