From 68aced362cfab4ea0ef0c657b262f533f9481002 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 3 Sep 2022 13:58:42 +0800 Subject: [PATCH] [gnc-ab-utils] concise string accumulator --- gnucash/import-export/aqb/gnc-ab-utils.c | 50 ++++-------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/gnucash/import-export/aqb/gnc-ab-utils.c b/gnucash/import-export/aqb/gnc-ab-utils.c index e5df692254..fdeb368c07 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 *