mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
use icu::ListFormatter to combine a list strings into a string
This commit is contained in:
parent
fc0e80bbad
commit
ab7ead39ca
@ -46,6 +46,7 @@
|
||||
|
||||
#include <cinttypes>
|
||||
#include <unicode/calendar.h>
|
||||
#include <unicode/listformatter.h>
|
||||
|
||||
#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<icu::UnicodeString> strvec;
|
||||
icu::UnicodeString result;
|
||||
std::string retval;
|
||||
|
||||
for (auto n = strings; n; n = g_list_next (n))
|
||||
strvec.push_back (static_cast<char*>(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());
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
//@}
|
||||
|
||||
//@}
|
||||
|
Loading…
Reference in New Issue
Block a user