From a82c72cfb9c53f5f8d2b93a87cd707e489a7b4f5 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Fri, 9 Sep 2022 14:57:51 -0700 Subject: [PATCH] [price-quotes] Remove level of indirection when parsing quote data. --- libgnucash/app-utils/gnc-quotes.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libgnucash/app-utils/gnc-quotes.cpp b/libgnucash/app-utils/gnc-quotes.cpp index 90a4072df9..b743e5acbf 100644 --- a/libgnucash/app-utils/gnc-quotes.cpp +++ b/libgnucash/app-utils/gnc-quotes.cpp @@ -360,36 +360,37 @@ GncQuotesImpl::parse_one_quote(const bpt::ptree& pt, gnc_commodity* comm) if (gnc_commodity_equiv(comm, m_dflt_curr) || (!comm_mnemonic || (strcmp (comm_mnemonic, "XXX") == 0))) return nullptr; - if (pt.find (comm_mnemonic) == pt.not_found()) + auto comm_pt_ai{pt.find(comm_mnemonic)}; + if (comm_pt_ai == pt.not_found()) { PINFO("Skipped %s:%s - Finance::Quote didn't return any data.", comm_ns, comm_mnemonic); return nullptr; } - std::string key = comm_mnemonic; - auto success = pt.get_optional (key + ".success"); + auto comm_pt{comm_pt_ai->second}; + auto success = comm_pt.get_optional ("success"); std::string price_type = "last"; - auto price_str = pt.get_optional (key + "." + price_type); + auto price_str = comm_pt.get_optional (price_type); if (!price_str) { price_type = "nav"; - price_str = pt.get_optional (key + "." + price_type); + price_str = comm_pt.get_optional (price_type); } if (!price_str) { price_type = "price"; - price_str = pt.get_optional (key + "." + price_type); + price_str = comm_pt.get_optional (price_type); /* guile wrapper used "unknown" as price type when "price" was found, * reproducing here to keep same result for users in the pricedb */ price_type = "unknown"; } - auto inverted_tmp = pt.get_optional (key + ".inverted"); + auto inverted_tmp = comm_pt.get_optional ("inverted"); auto inverted = inverted_tmp ? *inverted_tmp : false; - auto date_str = pt.get_optional (key + ".date"); - auto time_str = pt.get_optional (key + ".time"); - auto currency_str = pt.get_optional (key + ".currency"); + auto date_str = comm_pt.get_optional ("date"); + auto time_str = comm_pt.get_optional ("time"); + auto currency_str = comm_pt.get_optional ("currency"); PINFO("Commodity: %s", comm_mnemonic); @@ -401,7 +402,7 @@ GncQuotesImpl::parse_one_quote(const bpt::ptree& pt, gnc_commodity* comm) if (!success || !*success) { - auto errmsg = pt.get_optional (key + ".errormsg"); + auto errmsg = comm_pt.get_optional ("errormsg"); PWARN("Skipped %s:%s - Finance::Quote returned fetch failure.\nReason %s", comm_ns, comm_mnemonic, (errmsg ? errmsg->c_str() : "unknown"));