+/* Converts the INPUT value into a UTF-8 encoded string, according to format
+ specification FORMAT.
+
+ VALUE must be the correct width for FORMAT, that is, its width must be
+ fmt_var_width(FORMAT).
+
+ ENCODING must be the encoding of INPUT. Normally this can be obtained by
+ calling dict_get_encoding() on the dictionary with which INPUT is
+ associated. ENCODING is only important when FORMAT's type is FMT_A.
+
+ The return value is dynamically allocated, and must be freed by the caller.
+ If POOL is non-null, then the return value is allocated on that pool. */
+char *
+data_out_pool (const union value *input, const char *encoding,
+ const struct fmt_spec *format, struct pool *pool)
+{
+ assert (fmt_check_output (format));
+ if (format->type == FMT_A)
+ {
+ char *in = CHAR_CAST (char *, value_str (input, format->w));
+ return recode_string_pool (UTF8, encoding, in, format->w, pool);
+ }
+ else if (fmt_get_category (format->type) == FMT_CAT_BINARY)
+ {
+ char tmp[16];
+
+ assert (format->w + 1 <= sizeof tmp);
+ converters[format->type] (input, format, tmp);
+ return binary_to_utf8 (tmp, pool);
+ }
+ else
+ {
+ const struct fmt_number_style *style = settings_get_style (format->type);
+ size_t size = format->w + style->extra_bytes + 1;
+ char *output;
+
+ output = pool_alloc_unaligned (pool, size);
+ converters[format->type] (input, format, output);
+ return output;
+ }
+}
+
+/* Like data_out_pool(), except that for basic numeric formats (F, COMMA, DOT,
+ COLLAR, PCT, E) and custom currency formats are formatted as wide as
+ necessary to fully display the selected number of decimal places. */
+char *
+data_out_stretchy (const union value *input, const char *encoding,
+ const struct fmt_spec *format, struct pool *pool)
+{
+ struct fmt_spec wide_format;
+
+ if (fmt_get_category (format->type) & (FMT_CAT_BASIC | FMT_CAT_CUSTOM))
+ {
+ /* XXX In the common case this wastes memory for 40 bytes of mostly
+ spaces. */
+ wide_format.type = format->type;
+ wide_format.w = 40;
+ wide_format.d = format->d;
+ format = &wide_format;
+ }
+
+ return data_out_pool (input, encoding, format, pool);
+}
+
+char *
+data_out (const union value *input, const char *encoding, const struct fmt_spec *format)