From ab7ead39ca8426079318ac28bb4bdd3b7140cd25 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 2 Oct 2023 12:28:09 +0800 Subject: [PATCH 1/3] use icu::ListFormatter to combine a list strings into a string --- libgnucash/engine/gnc-date.cpp | 27 +++++++++++++++++++++++++++ libgnucash/engine/gnc-date.h | 11 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp index c44912efa7..7abbddaf8a 100644 --- a/libgnucash/engine/gnc-date.cpp +++ b/libgnucash/engine/gnc-date.cpp @@ -46,6 +46,7 @@ #include #include +#include #include "gnc-date.h" #include "gnc-date-p.h" @@ -1652,3 +1653,29 @@ gnc_date_load_funcs (void) Testfuncs *tf = g_slice_new (Testfuncs); return tf; } + + +gchar* +gnc_list_formatter (GList *strings) +{ + g_return_val_if_fail (strings, nullptr); + + UErrorCode status = U_ZERO_ERROR; + auto formatter = icu::ListFormatter::createInstance(status); + std::vector strvec; + icu::UnicodeString result; + std::string retval; + + for (auto n = strings; n; n = g_list_next (n)) + strvec.push_back (static_cast(n->data)); + + formatter->format (strvec.data(), strvec.size(), result, status); + + if (U_FAILURE(status)) + PERR ("Unicode error"); + else + result.toUTF8String(retval); + + delete formatter; + return g_strdup (retval.c_str()); +} diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h index 2193d0de10..fcf2ff5f55 100644 --- a/libgnucash/engine/gnc-date.h +++ b/libgnucash/engine/gnc-date.h @@ -813,6 +813,17 @@ void gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end); * fiscal year. The year field of this argument is ignored. */ void gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end); + + +/** This function takes a GList of char*, and uses locale-sensitive + * list formatter. + * + * @param strings The GList* of char*. + * + * @returns a newly allocated char* + */ +gchar* gnc_list_formatter (GList* strings); + //@} //@} From 8a54bf26580cb138f32f8386646806d5383c068e Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 2 Oct 2023 12:28:29 +0800 Subject: [PATCH 2/3] use gnc_list_formatter instead of gnc_g_list_stringjoin (..., ", "); --- gnucash/gnome/gnc-plugin-page-register.c | 4 ++-- gnucash/import-export/import-main-matcher.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c index c9bee2493e..fe902f69a8 100644 --- a/gnucash/gnome/gnc-plugin-page-register.c +++ b/gnucash/gnome/gnc-plugin-page-register.c @@ -3230,7 +3230,7 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page) if (show) { - char *str = gnc_g_list_stringjoin (show, ", "); + char *str = gnc_list_formatter (show); t_list = g_list_prepend (t_list, g_strdup_printf ("%s %s", _("Show:"), str)); g_free (str); @@ -3238,7 +3238,7 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page) if (hide) { - char *str = gnc_g_list_stringjoin (hide, ", "); + char *str = gnc_list_formatter (hide); t_list = g_list_prepend (t_list, g_strdup_printf ("%s %s", _("Hide:"), str)); g_free (str); diff --git a/gnucash/import-export/import-main-matcher.cpp b/gnucash/import-export/import-main-matcher.cpp index 5a8eb41ca2..003cb229de 100644 --- a/gnucash/import-export/import-main-matcher.cpp +++ b/gnucash/import-export/import-main-matcher.cpp @@ -1876,7 +1876,7 @@ get_peer_acct_names (Split *split) g_free (name); } names = g_list_sort (names, (GCompareFunc)g_utf8_collate); - gchar *retval = gnc_g_list_stringjoin (names, ", "); + auto retval = gnc_list_formatter (names); g_list_free_full (names, g_free); g_list_free (accounts_seen); return retval; From ae58c12601d4a89643080744e5abe32574c7b59d Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 10 Nov 2023 18:56:07 +0800 Subject: [PATCH 3/3] [import-main-matcher] don't quote account fullnames --- gnucash/import-export/import-main-matcher.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gnucash/import-export/import-main-matcher.cpp b/gnucash/import-export/import-main-matcher.cpp index 003cb229de..ef2991d523 100644 --- a/gnucash/import-export/import-main-matcher.cpp +++ b/gnucash/import-export/import-main-matcher.cpp @@ -1871,9 +1871,8 @@ get_peer_acct_names (Split *split) (g_list_find (accounts_seen, account))) continue; gchar *name = gnc_account_get_full_name (account); - names = g_list_prepend (names, g_strdup_printf ("\"%s\"", name)); + names = g_list_prepend (names, name); accounts_seen = g_list_prepend (accounts_seen, account); - g_free (name); } names = g_list_sort (names, (GCompareFunc)g_utf8_collate); auto retval = gnc_list_formatter (names);