+ VALUE must be the correct width for FORMAT, that is, its width must be
+ fmt_var_width(FORMAT).
+
+ INPUT_ENCODING can normally 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. */
+void
+data_out_recode (const union value *input, const char *input_encoding,
+ const struct fmt_spec *format,
+ struct string *output, const char *output_encoding)
+{
+ assert (fmt_check_output (format));
+ if (format->type == FMT_A)
+ {
+ char *in = CHAR_CAST (char *, value_str (input, format->w));
+ char *out = recode_string (output_encoding, input_encoding,
+ in, format->w);
+ ds_put_cstr (output, out);
+ free (out);
+ }
+ else if (fmt_get_category (format->type) == FMT_CAT_BINARY)
+ converters[format->type] (input, format,
+ ds_put_uninit (output, format->w));
+ else
+ {
+ char *utf8_encoded = data_out (input, input_encoding, format);
+ char *output_encoded = recode_string (output_encoding, UTF8,
+ utf8_encoded, -1);
+ ds_put_cstr (output, output_encoded);
+ free (output_encoded);
+ free (utf8_encoded);
+ }