for (i = 0; i < pt->n_consts; i++)
{
const struct variable *var = pt->const_vars[i];
+ size_t ofs;
+
ds_put_format (&title, ", %s=", var_get_name (var));
+
+ /* Insert the formatted value of the variable, then trim
+ leading spaces in what was just inserted. */
+ ofs = ds_length (&title);
data_out (&pt->const_values[i], var_get_print_format (var),
ds_put_uninit (&title, var_get_width (var)));
- /* XXX remove any leading space in what was just inserted. */
+ ds_remove (&title, ofs, ss_cspan (ds_substr (&title, ofs, SIZE_MAX),
+ ss_cstr (" ")));
}
ds_put_cstr (&title, " [");
st->ss.length = new_length;
}
+/* Removes N characters from ST starting at offset START. */
+void
+ds_remove (struct string *st, size_t start, size_t n)
+{
+ if (n > 0 && start < st->ss.length)
+ {
+ if (st->ss.length - start <= n)
+ {
+ /* All characters at or beyond START are deleted. */
+ st->ss.length = start;
+ }
+ else
+ {
+ /* Some characters remain and must be shifted into
+ position. */
+ memmove (st->ss.string + st->ss.length,
+ st->ss.string + st->ss.length + n,
+ st->ss.length - start - n);
+ st->ss.length -= n;
+ }
+ }
+ else
+ {
+ /* There are no characters to delete or no characters at or
+ beyond START, hence deletion is a no-op. */
+ }
+}
+
/* Returns true if ST is empty, false otherwise. */
bool
ds_is_empty (const struct string *st)
size_t *save_idx, struct substring *token);
void ds_rpad (struct string *, size_t length, char pad);
void ds_set_length (struct string *, size_t new_length, char pad);
+void ds_remove (struct string *, size_t start, size_t n);
/* Extracting substrings. */
struct substring ds_ss (const struct string *);