diff --git a/gnucash/gnome-utils/dialog-commodity.cpp b/gnucash/gnome-utils/dialog-commodity.cpp index 5f64ee845c..87880a8b1e 100644 --- a/gnucash/gnome-utils/dialog-commodity.cpp +++ b/gnucash/gnome-utils/dialog-commodity.cpp @@ -429,15 +429,6 @@ gnc_ui_select_commodity_namespace_changed_cb (GtkComboBox *cbwe, /******************************************************************** * gnc_ui_update_commodity_picker ********************************************************************/ -static int -collate(gconstpointer a, gconstpointer b) -{ - if (!a) - return -1; - if (!b) - return 1; - return g_utf8_collate (static_cast(a), static_cast(b)); -} void @@ -445,15 +436,13 @@ gnc_ui_update_commodity_picker (GtkWidget *cbwe, const gchar * name_space, const gchar * init_string) { - GList * iterator = nullptr; - GList * commodity_items = nullptr; + std::vector commodity_items; GtkComboBox *combo_box; GtkEntry *entry; GtkTreeModel *model; GtkTreeIter iter; gnc_commodity_table *table; gint current = 0, match = 0; - gchar *name; g_return_if_fail(GTK_IS_COMBO_BOX(cbwe)); g_return_if_fail(name_space); @@ -470,25 +459,23 @@ gnc_ui_update_commodity_picker (GtkWidget *cbwe, gtk_combo_box_set_active(combo_box, -1); table = gnc_commodity_table_get_table (gnc_get_current_book ()); + for (auto comm : gnc_commodity_table_get_commodities(table, name_space)) - { - commodity_items = g_list_prepend (commodity_items, (gpointer) gnc_commodity_get_printname(comm)); - } + commodity_items.push_back (gnc_commodity_get_printname(comm)); - commodity_items = g_list_sort(commodity_items, collate); - for (iterator = commodity_items; iterator; iterator = iterator->next) + std::sort (commodity_items.end(), commodity_items.begin()); + + for (auto name : commodity_items) { - name = (char *)iterator->data; gtk_list_store_append(GTK_LIST_STORE(model), &iter); - gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, name, -1); + gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, name.c_str(), -1); - if (init_string && g_utf8_collate(name, init_string) == 0) + if (init_string && name == init_string) match = current; current++; } gtk_combo_box_set_active(combo_box, match); - g_list_free(commodity_items); } diff --git a/gnucash/import-export/import-commodity-matcher.cpp b/gnucash/import-export/import-commodity-matcher.cpp index 948f32b036..cbf27fa839 100644 --- a/gnucash/import-export/import-commodity-matcher.cpp +++ b/gnucash/import-export/import-commodity-matcher.cpp @@ -24,6 +24,7 @@ @author Copyright (C) 2002 Benoit Grégoire */ #include +#include #include #include @@ -70,18 +71,16 @@ gnc_commodity * gnc_import_select_commodity(const char * cusip, { auto ns = ns_str.c_str(); DEBUG("Looking at namespace %s", ns); - for (auto com : gnc_commodity_table_get_commodities (commodity_table, ns)) + auto commodities{gnc_commodity_table_get_commodities (commodity_table, ns)}; + auto it = std::find_if (commodities.begin(), commodities.end(), + [cusip](auto com) + { return !g_strcmp0 (gnc_commodity_get_cusip (com), cusip); }); + if (it != commodities.end()) { - DEBUG("Looking at commodity %s", gnc_commodity_get_fullname (com)); - if (!g_strcmp0 (gnc_commodity_get_cusip (com), cusip)) - { - retval = com; - DEBUG("Commodity %s matches.", gnc_commodity_get_fullname (com)); - break; - } - } - if (retval) + retval = *it; + DEBUG("Commodity %s matches.", gnc_commodity_get_fullname (*it)); break; + }; } if (retval == NULL && ask_on_unknown != 0)