+ return is_str_user_missing (mv, s) ? MV_USER : 0;
+}
+
+/* Like mv_is_value_missing(), this tests whether V is a missing value in MV.
+ It supports the uncommon case where V and MV might have different widths:
+ the caller must specify VW, the width of V. MV and VW must be both numeric
+ or both string.
+
+ Comparison of strings of different width is done by conceptually extending
+ both strings to infinite width by appending spaces. */
+enum mv_class
+mv_is_value_missing_varwidth (const struct missing_values *mv,
+ const union value *v, int vw)
+{
+ int mvw = mv->width;
+ if (mvw == vw)
+ return mv_is_value_missing (mv, v);
+
+ /* Make sure they're both strings. */
+ assert (mvw && vw);
+ if (mv->type == MVT_NONE)
+ return false;
+
+ for (int i = 0; i < mv->type; i++)
+ if (!buf_compare_rpad (CHAR_CAST_BUG (const char *, mv->values[i].s), mvw,
+ CHAR_CAST_BUG (const char *, v->s), vw))
+ return MV_USER;
+ return 0;
+}
+
+char *
+mv_to_string (const struct missing_values *mv, const char *encoding)
+{
+ struct string s = DS_EMPTY_INITIALIZER;
+ if (mv_has_range (mv))
+ {
+ double x, y;
+ mv_get_range (mv, &x, &y);
+ if (x == LOWEST)
+ ds_put_format (&s, "LOWEST THRU %.*g", DBL_DIG + 1, y);
+ else if (y == HIGHEST)
+ ds_put_format (&s, "%.*g THRU HIGHEST", DBL_DIG + 1, x);
+ else
+ ds_put_format (&s, "%.*g THRU %.*g",
+ DBL_DIG + 1, x,
+ DBL_DIG + 1, y);
+ }
+ for (size_t j = 0; j < mv_n_values (mv); j++)
+ {
+ const union value *value = mv_get_value (mv, j);
+ if (!ds_is_empty (&s))
+ ds_put_cstr (&s, "; ");
+ if (!mv->width)
+ ds_put_format (&s, "%.*g", DBL_DIG + 1, value->f);
+ else
+ {
+ char *mvs = recode_string (
+ "UTF-8", encoding, CHAR_CAST (char *, value->s),
+ MIN (mv->width, MV_MAX_STRING));
+ ds_put_format (&s, "\"%s\"", mvs);
+ free (mvs);
+ }
+ }
+ return ds_is_empty (&s) ? NULL : ds_steal_cstr (&s);