Skip to content

Commit 8f7eecd

Browse files
Merge branch 'icu-list-formatter' into stable #1791
2 parents e6a30f7 + ae58c12 commit 8f7eecd

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

gnucash/gnome/gnc-plugin-page-register.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,15 +3230,15 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page)
32303230

32313231
if (show)
32323232
{
3233-
char *str = gnc_g_list_stringjoin (show, ", ");
3233+
char *str = gnc_list_formatter (show);
32343234
t_list = g_list_prepend
32353235
(t_list, g_strdup_printf ("%s %s", _("Show:"), str));
32363236
g_free (str);
32373237
}
32383238

32393239
if (hide)
32403240
{
3241-
char *str = gnc_g_list_stringjoin (hide, ", ");
3241+
char *str = gnc_list_formatter (hide);
32423242
t_list = g_list_prepend
32433243
(t_list, g_strdup_printf ("%s %s", _("Hide:"), str));
32443244
g_free (str);

gnucash/import-export/import-main-matcher.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,12 +1871,11 @@ get_peer_acct_names (Split *split)
18711871
(g_list_find (accounts_seen, account)))
18721872
continue;
18731873
gchar *name = gnc_account_get_full_name (account);
1874-
names = g_list_prepend (names, g_strdup_printf ("\"%s\"", name));
1874+
names = g_list_prepend (names, name);
18751875
accounts_seen = g_list_prepend (accounts_seen, account);
1876-
g_free (name);
18771876
}
18781877
names = g_list_sort (names, (GCompareFunc)g_utf8_collate);
1879-
gchar *retval = gnc_g_list_stringjoin (names, ", ");
1878+
auto retval = gnc_list_formatter (names);
18801879
g_list_free_full (names, g_free);
18811880
g_list_free (accounts_seen);
18821881
return retval;

libgnucash/engine/gnc-date.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#include <cinttypes>
4848
#include <unicode/calendar.h>
49+
#include <unicode/listformatter.h>
4950

5051
#include "gnc-date.h"
5152
#include "gnc-date-p.h"
@@ -1656,3 +1657,29 @@ gnc_date_load_funcs (void)
16561657
Testfuncs *tf = g_slice_new (Testfuncs);
16571658
return tf;
16581659
}
1660+
1661+
1662+
gchar*
1663+
gnc_list_formatter (GList *strings)
1664+
{
1665+
g_return_val_if_fail (strings, nullptr);
1666+
1667+
UErrorCode status = U_ZERO_ERROR;
1668+
auto formatter = icu::ListFormatter::createInstance(status);
1669+
std::vector<icu::UnicodeString> strvec;
1670+
icu::UnicodeString result;
1671+
std::string retval;
1672+
1673+
for (auto n = strings; n; n = g_list_next (n))
1674+
strvec.push_back (static_cast<char*>(n->data));
1675+
1676+
formatter->format (strvec.data(), strvec.size(), result, status);
1677+
1678+
if (U_FAILURE(status))
1679+
PERR ("Unicode error");
1680+
else
1681+
result.toUTF8String(retval);
1682+
1683+
delete formatter;
1684+
return g_strdup (retval.c_str());
1685+
}

libgnucash/engine/gnc-date.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,17 @@ void gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end);
813813
* fiscal year. The year field of this argument is ignored. */
814814
void gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end);
815815

816+
817+
818+
/** This function takes a GList of char*, and uses locale-sensitive
819+
* list formatter.
820+
*
821+
* @param strings The GList* of char*.
822+
*
823+
* @returns a newly allocated char*
824+
*/
825+
gchar* gnc_list_formatter (GList* strings);
826+
816827
//@}
817828

818829
//@}

0 commit comments

Comments
 (0)