From c87d480b0de8d40ef756b52668b62e89d29300c4 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sat, 6 Jan 2024 18:16:31 -0800 Subject: [PATCH] Move gnc_list_formatter from gnc-date to gnc-ui-util. It has nothing at all to do with dates. --- libgnucash/app-utils/gnc-ui-util.cpp | 31 ++++++++++++++++++++++++++++ libgnucash/app-utils/gnc-ui-util.h | 9 ++++++++ libgnucash/engine/gnc-date.cpp | 30 --------------------------- libgnucash/engine/gnc-date.h | 11 ---------- 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/libgnucash/app-utils/gnc-ui-util.cpp b/libgnucash/app-utils/gnc-ui-util.cpp index 1f3ec059cc8..bfbf5bd0e3f 100644 --- a/libgnucash/app-utils/gnc-ui-util.cpp +++ b/libgnucash/app-utils/gnc-ui-util.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "qof.h" #include "gnc-prefs.h" @@ -62,6 +63,8 @@ #define GNC_PREF_REVERSED_ACCTS_INC_EXP "reversed-accounts-incomeexpense" #define GNC_PREF_PRICES_FORCE_DECIMAL "force-price-decimal" +using UniStr = icu::UnicodeString; + static QofLogModule log_module = GNC_MOD_GUI; static bool auto_decimal_enabled = false; @@ -2281,3 +2284,31 @@ gnc_filter_text_for_currency_commodity (const gnc_commodity *comm, return gnc_filter_text_for_currency_symbol (incoming_text, *symbol); } + +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; + UniStr result; + std::string retval; + + for (auto n = strings; n; n = g_list_next (n)) + { + auto utf8_str{static_cast(n->data)}; + strvec.push_back (UniStr::fromUTF8(utf8_str)); + } + + 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/app-utils/gnc-ui-util.h b/libgnucash/app-utils/gnc-ui-util.h index 044576f596a..51b8edb42eb 100644 --- a/libgnucash/app-utils/gnc-ui-util.h +++ b/libgnucash/app-utils/gnc-ui-util.h @@ -458,6 +458,15 @@ char* gnc_filter_text_for_currency_commodity (const gnc_commodity *comm, const char* incoming_text, const char** symbol); +/** 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); + #ifdef __cplusplus } #endif diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp index 20ea9f3b088..ab6ef981c24 100644 --- a/libgnucash/engine/gnc-date.cpp +++ b/libgnucash/engine/gnc-date.cpp @@ -46,7 +46,6 @@ #include #include -#include #include "gnc-date.h" #include "gnc-date-p.h" @@ -1651,32 +1650,3 @@ 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)) - { - auto utf8_str{static_cast(n->data)}; - strvec.push_back (icu::UnicodeString::fromUTF8(utf8_str)); - } - - 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 fcf2ff5f554..2193d0de107 100644 --- a/libgnucash/engine/gnc-date.h +++ b/libgnucash/engine/gnc-date.h @@ -813,17 +813,6 @@ 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); - //@} //@}