gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Tue Sep 6 06:53:57 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/68aced36 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ecd2cdf4 (commit)
	from  https://github.com/Gnucash/gnucash/commit/0f134714 (commit)



commit 68aced362cfab4ea0ef0c657b262f533f9481002
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Sep 3 13:58:42 2022 +0800

    [gnc-ab-utils] concise string accumulator

diff --git a/gnucash/import-export/aqb/gnc-ab-utils.c b/gnucash/import-export/aqb/gnc-ab-utils.c
index e5df69225..fdeb368c0 100644
--- a/gnucash/import-export/aqb/gnc-ab-utils.c
+++ b/gnucash/import-export/aqb/gnc-ab-utils.c
@@ -510,50 +510,16 @@ ab_ultimate_creditor_debtor_to_gnc (const AB_TRANSACTION *ab_trans,
 gchar *
 gnc_ab_description_to_gnc (const AB_TRANSACTION *ab_trans, gboolean is_ofx)
 {
-    /* Description */
-    gchar *description = gnc_ab_get_purpose (ab_trans, is_ofx);
-    gchar *other_name = gnc_ab_get_remote_name (ab_trans);
-    gchar *ultimate = ab_ultimate_creditor_debtor_to_gnc (ab_trans, is_ofx);
-    gchar *retval = NULL;
-
-    if (ultimate)
-        retval = ultimate;
-    if (description)
-    {
-        if (retval)
-        {
-            char *tmp = g_strdup_printf ("%s; %s", retval, description);
-            g_free (retval);
-            g_free (description);
-            retval = tmp;
-        }
-        else
-        {
-            retval = description;
-        }
-    }
-
-    if (other_name)
-    {
-        if (retval)
-        {
-            char *tmp = g_strdup_printf ("%s; %s", retval, other_name);
-            g_free (retval);
-            g_free (other_name);
-            retval = tmp;
-        }
-        else
-        {
-            retval = other_name;
-        }
-    }
+    GList *acc = NULL;
+    gchar *retval;
 
-    if (!retval)
-    {
-        retval = g_strdup (_("Unspecified"));
-    }
+    acc = g_list_prepend (acc, gnc_ab_get_remote_name (ab_trans));
+    acc = g_list_prepend (acc, gnc_ab_get_purpose (ab_trans, is_ofx));
+    acc = g_list_prepend (acc, ab_ultimate_creditor_debtor_to_gnc (ab_trans, is_ofx));
+    retval = gnc_g_list_stringjoin (acc, "; ");
 
-    return retval;
+    g_list_free_full (acc, g_free);
+    return retval ? retval : g_strdup (_("Unspecified"));
 }
 
 gchar *

commit ecd2cdf425a9e73aa578f5bddfe554e5d88eb43b
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Tue Sep 6 09:21:52 2022 +0800

    [gnc-glib-utils] gnc_g_list_stringjoin skips NULL data

diff --git a/libgnucash/core-utils/gnc-glib-utils.c b/libgnucash/core-utils/gnc-glib-utils.c
index 7bb2ba533..4c10c6fae 100644
--- a/libgnucash/core-utils/gnc-glib-utils.c
+++ b/libgnucash/core-utils/gnc-glib-utils.c
@@ -335,18 +335,25 @@ gnc_g_list_stringjoin (GList *list_of_strings, const gchar *sep)
     gint length = -seplen;
     gchar *retval, *p;
 
-    if (!list_of_strings)
-        return NULL;
-
     for (GList *n = list_of_strings; n; n = n->next)
-        length += strlen ((gchar*)n->data) + seplen;
+    {
+        gchar *str = n->data;
+        if (str && *str)
+            length += strlen (str) + seplen;
+    }
+
+    if (length <= 0)
+        return NULL;
 
     p = retval = (gchar*) g_malloc0 (length * sizeof (gchar) + 1);
     for (GList *n = list_of_strings; n; n = n->next)
     {
-        p = g_stpcpy (p, (gchar*)n->data);
-        if (n->next && sep)
+        gchar *str = n->data;
+        if (!str || !str[0])
+            continue;
+        if (sep && (p != retval))
             p = g_stpcpy (p, sep);
+        p = g_stpcpy (p, str);
     }
 
     return retval;
diff --git a/libgnucash/core-utils/test/test-gnc-glib-utils.c b/libgnucash/core-utils/test/test-gnc-glib-utils.c
index 0c59356e3..a350cfaf5 100644
--- a/libgnucash/core-utils/test/test-gnc-glib-utils.c
+++ b/libgnucash/core-utils/test/test-gnc-glib-utils.c
@@ -79,6 +79,11 @@ test_g_list_stringjoin (gconstpointer data)
     g_assert_cmpstr (ret, ==, "one");
     g_free (ret);
 
+   /* The following inserts a NULL between "two" and "one". As a
+       result, the stringjoin effectively skips a step, i.e. it does
+       not insert separator repeatedly between NULL strings */
+    test = g_list_prepend (test, NULL);
+
     test = g_list_prepend (test, "two");
 
     ret = gnc_g_list_stringjoin (test, NULL);



Summary of changes:
 gnucash/import-export/aqb/gnc-ab-utils.c         | 50 ++++--------------------
 libgnucash/core-utils/gnc-glib-utils.c           | 19 ++++++---
 libgnucash/core-utils/test/test-gnc-glib-utils.c |  5 +++
 3 files changed, 26 insertions(+), 48 deletions(-)



More information about the gnucash-changes mailing list