+ 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,
+ struct fmt_spec format, const struct fmt_settings *settings,
+ struct string *output, const char *output_encoding)
+{
+ assert (fmt_check_output (format));
+ if (format.type == FMT_A)
+ {
+ char *in = CHAR_CAST (char *, input->s);
+ 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, settings,
+ ds_put_uninit (output, format.w));
+ else
+ {
+ char *utf8_encoded = data_out (input, input_encoding, format, settings);
+ char *output_encoded = recode_string (output_encoding, UTF8,
+ utf8_encoded, -1);
+ ds_put_cstr (output, output_encoded);
+ free (output_encoded);
+ free (utf8_encoded);
+ }