pivot-table: Allow all pivot_value formatting functions to use defaults.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 12 Aug 2022 17:15:33 +0000 (10:15 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 28 Aug 2022 21:22:19 +0000 (14:22 -0700)
src/output/output-item.c
src/output/pivot-table.c
src/output/pivot-table.h

index a4328b52e99725be3d9d568db3c31f4adfc8495b..6b7c11121c588d998e09797d569122ed1fe565fb 100644 (file)
@@ -366,7 +366,7 @@ output_item_dump (const struct output_item *item, int indentation)
 
     case OUTPUT_ITEM_TEXT:
       {
-        char *s = pivot_value_to_string_defaults (item->text.content);
+        char *s = pivot_value_to_string (item->text.content, NULL);
         printf ("text %s \"%s\"\n",
                 text_item_subtype_to_string (item->text.subtype), s);
         free (s);
@@ -625,7 +625,7 @@ char *
 text_item_get_plain_text (const struct output_item *item)
 {
   assert (item->type == OUTPUT_ITEM_TEXT);
-  return pivot_value_to_string_defaults (item->text.content);
+  return pivot_value_to_string (item->text.content, NULL);
 }
 
 static bool
index f8f917d9dd1d965b3d5b2830b725c7c12004eee1..8ecbd361a5e6b31566ee85ea0fb29f14d387c287 100644 (file)
@@ -2372,8 +2372,15 @@ get_text_from_markup (const char *markup, struct string *out)
   xmlFreeParserCtxt (parser);
 }
 
-/* Appends a text representation of the body of VALUE to OUT.  Settings on
-   PT control whether variable and value labels are included.
+static const struct pivot_table pivot_value_format_defaults = {
+  .show_values = SETTINGS_VALUE_SHOW_DEFAULT,
+  .show_variables = SETTINGS_VALUE_SHOW_DEFAULT,
+  .settings = FMT_SETTINGS_INIT,
+};
+
+/* Appends a text representation of the body of VALUE to OUT.  Settings on PT
+   control whether variable and value labels are included (pass NULL for PT to
+   get default formatting in the absence of a pivot table).
 
    The "body" omits subscripts and superscripts and footnotes.
 
@@ -2381,9 +2388,10 @@ get_text_from_markup (const char *markup, struct string *out)
    otherwise.  */
 bool
 pivot_value_format_body (const struct pivot_value *value,
-                         const struct pivot_table *pt,
+                         const struct pivot_table *pt_,
                          struct string *out)
 {
+  const struct pivot_table *pt = pt_ ? pt_ : &pivot_value_format_defaults;
   enum settings_value_show show;
   bool numeric = false;
 
@@ -2474,8 +2482,9 @@ pivot_value_format_body (const struct pivot_value *value,
   return numeric;
 }
 
-/* Appends a text representation of VALUE to OUT.  Settings on
-   PT control whether variable and value labels are included.
+/* Appends a text representation of VALUE to OUT.  Settings on PT control
+   whether variable and value labels are included (pass NULL for PT to get
+   default formatting in the absence of a pivot table).
 
    Subscripts and footnotes are included.
 
@@ -2483,9 +2492,10 @@ pivot_value_format_body (const struct pivot_value *value,
    otherwise.  */
 bool
 pivot_value_format (const struct pivot_value *value,
-                    const struct pivot_table *pt,
+                    const struct pivot_table *pt_,
                     struct string *out)
 {
+  const struct pivot_table *pt = pt_ ? pt_ : &pivot_value_format_defaults;
   bool numeric = pivot_value_format_body (value, pt, out);
 
   const struct pivot_value_ex *ex = value->ex;
@@ -2513,7 +2523,9 @@ pivot_value_format (const struct pivot_value *value,
 }
 
 /* Returns a text representation of VALUE.  The caller must free the string,
-   with free(). */
+   with free().  Settings on PT control whether variable and value labels are
+   included (pass NULL for PT to get default formatting in the absence of a
+   pivot table). */
 char *
 pivot_value_to_string (const struct pivot_value *value,
                        const struct pivot_table *pt)
@@ -2523,17 +2535,6 @@ pivot_value_to_string (const struct pivot_value *value,
   return ds_steal_cstr (&s);
 }
 
-char *
-pivot_value_to_string_defaults (const struct pivot_value *value)
-{
-  static const struct pivot_table pt = {
-    .show_values = SETTINGS_VALUE_SHOW_DEFAULT,
-    .show_variables = SETTINGS_VALUE_SHOW_DEFAULT,
-    .settings = FMT_SETTINGS_INIT,
-  };
-  return pivot_value_to_string (value, &pt);
-}
-
 struct pivot_value *
 pivot_value_clone (const struct pivot_value *old)
 {
index e374596184889f107ba2ecdfef60f44b3be671c8..1428a921d754795e21a6f21e8483b46415bfcbb0 100644 (file)
@@ -770,7 +770,6 @@ void pivot_value_set_rc (const struct pivot_table *, struct pivot_value *,
 /* Converting a pivot_value to a string for display. */
 char *pivot_value_to_string (const struct pivot_value *,
                              const struct pivot_table *);
-char *pivot_value_to_string_defaults (const struct pivot_value *);
 bool pivot_value_format (const struct pivot_value *,
                          const struct pivot_table *, struct string *);
 bool pivot_value_format_body (const struct pivot_value *,