str: Add function xstrdup_if_nonnull() and introduce many users.
[pspp] / src / output / spv / spv-output.c
index c21ec22bcb29bc0c80dfd98cc41462e24aeea527..49cc195341d8c77351939f8c7d9fa10204701f08 100644 (file)
@@ -28,19 +28,11 @@ void
 spv_text_submit (const struct spv_item *in)
 {
   enum spv_item_class class = spv_item_get_class (in);
-  enum text_item_type type
-    = (class == SPV_CLASS_HEADINGS ? TEXT_ITEM_TITLE
-       : class == SPV_CLASS_PAGETITLE ? TEXT_ITEM_PAGE_TITLE
-       : TEXT_ITEM_LOG);
-  const struct pivot_value *value = spv_item_get_text (in);
-  char *text = pivot_value_to_string_defaults (value);
-  char *label = in->label ? xstrdup (in->label) : NULL;
-  struct text_item *item = text_item_create_nocopy (type, text, label);
-
-  if (value->font_style)
-    {
-      font_style_uninit (&item->style);
-      font_style_copy (NULL, &item->style, value->font_style);
-    }
+  struct text_item *item = text_item_create_value (
+    (class == SPV_CLASS_HEADINGS ? TEXT_ITEM_TITLE
+     : class == SPV_CLASS_PAGETITLE ? TEXT_ITEM_PAGE_TITLE
+     : TEXT_ITEM_LOG),
+    pivot_value_clone (spv_item_get_text (in)),
+    xstrdup_if_nonnull (in->label));
   text_item_submit (item);
 }