gnucash maint: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Tue Feb 12 15:58:54 EST 2019
Updated via https://github.com/Gnucash/gnucash/commit/140eb0b1 (commit)
via https://github.com/Gnucash/gnucash/commit/67f5dfb0 (commit)
from https://github.com/Gnucash/gnucash/commit/bfadfd7d (commit)
commit 140eb0b110acba5bd6c1a837ae7d25891ea63c1f
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Feb 12 12:58:42 2019 -0800
Log a warning in gnc_get_locale() instead of writing to stderr.
diff --git a/libgnucash/core-utils/gnc-locale-utils.cpp b/libgnucash/core-utils/gnc-locale-utils.cpp
index 6707b39f4..28678c4e2 100644
--- a/libgnucash/core-utils/gnc-locale-utils.cpp
+++ b/libgnucash/core-utils/gnc-locale-utils.cpp
@@ -62,10 +62,13 @@ gnc_get_locale()
#else
char* locale = g_strdup(setlocale(LC_ALL, ""));
#endif
- std::string c_locale(locale);
- std::cerr << "[gnc_get_locale] Failed to create app-default locale from " << c_locale << " because " << err.what() << "\n";
- std::cerr << "[gnc_get_locale] Using the 'C' locale for C++\n";
+
+ g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+ "Failed to create C++ default locale from"
+ "%s because %s. Using the 'C' locale for C++.",
+ locale, err.what());
g_free(locale);
+ cached = std::locale::classic();
}
}
return cached;
commit 67f5dfb03499b5b57943ac68f684931594ecc0e0
Author: John Ralls <jralls at ceridwen.us>
Date: Tue Feb 12 12:53:13 2019 -0800
Bug 796946 - Mortgage and Loan Repayment Setup tool crashes when...
exiting "Loan Repayment Options" page.
Because libstdc++ on Windows doesn't support any C++ locales besides
"C" and throws an exception if you try.
To work around this use GetNumberFormatW (not GetCurrencyFormatW,
that includes the currency symbol) to create a formatted number string
with the right separators, grouping, and precision.
diff --git a/gnucash/gnome/assistant-loan.cpp b/gnucash/gnome/assistant-loan.cpp
index 5505623c1..5c84a2c4a 100644
--- a/gnucash/gnome/assistant-loan.cpp
+++ b/gnucash/gnome/assistant-loan.cpp
@@ -47,6 +47,9 @@ extern "C"
#include "gnc-ui-util.h"
#include "gnc-frequency.h"
#include "gnc-engine.h"
+#ifdef __MINGW32__
+#include <Windows.h>
+#endif
}
#include <gnc-locale-utils.hpp>
@@ -54,6 +57,9 @@ extern "C"
#include <string>
#include <sstream>
#include <iomanip>
+#ifdef __MINGW32__
+#include <codecvt>
+#endif
namespace bl = boost::locale;
@@ -2321,11 +2327,50 @@ struct cust_prec_punct : std::moneypunct_byname<wchar_t, false> {
template<int prec>
std::string to_str_with_prec (const gdouble val)
{
+#ifdef __MINGW32__
+ NUMBERFMTW numfmt;
+ LCID lcid = GetThreadLocale();
+ DWORD numval;
+
+ numfmt.NumDigits = prec;
+ GetLocaleInfoW(lcid, LOCALE_RETURN_NUMBER|LOCALE_ILZERO, (LPWSTR)&numval,
+ sizeof(numval)/sizeof(wchar_t));
+ numfmt.LeadingZero = numval;
+ wchar_t grouping[10];
+ GetLocaleInfoW(lcid, LOCALE_SGROUPING, grouping,
+ sizeof(grouping)/sizeof(wchar_t));
+ auto semi = wcschr(grouping, ';');
+ *semi = 0;
+ numfmt.Grouping = _wtoi(grouping);
+ wchar_t decsep[4];
+ GetLocaleInfoW(lcid, LOCALE_SDECIMAL, decsep,
+ sizeof(decsep)/sizeof(wchar_t) );
+ numfmt.lpDecimalSep = decsep;
+ wchar_t thousep[4];
+ GetLocaleInfoW(lcid, LOCALE_STHOUSAND, thousep,
+ sizeof(thousep)/sizeof(wchar_t));
+ numfmt.lpThousandSep = thousep;
+ GetLocaleInfoW(lcid, LOCALE_RETURN_NUMBER|LOCALE_INEGNUMBER,
+ (LPWSTR)&numval, sizeof(numval)/sizeof(wchar_t));
+ numfmt.NegativeOrder = numval;
+//Can't use std::to_wstring, it localizes with a C function.
+ std::wstringstream valstr;
+ valstr << val;
+ int size = GetNumberFormatW(lcid, 0, valstr.str().c_str(),
+ &numfmt, nullptr, 0);
+ wchar_t* buf = static_cast<wchar_t*>(malloc(sizeof(wchar_t) * size));
+ GetNumberFormatW(lcid, 0, valstr.str().c_str(), &numfmt, buf, size);
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conv;
+ std::string result = conv.to_bytes(buf);
+ free(buf);
+ return result;
+#else
auto loc = std::locale(gnc_get_locale(), new cust_prec_punct<prec>(""));
std::wstringstream valstr;
valstr.imbue(loc);
valstr << std::put_money(val * pow(10, prec));
return utf_to_utf<char>(valstr.str());
+#endif
}
static
@@ -2365,7 +2410,6 @@ loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar *t
period_rate = ldd->ld.interestRate / 100;
break;
}
-
auto period_rate_str = to_str_with_prec<5> (period_rate);
auto period_base_str = to_str_with_prec<2> (12.0);
auto periods_str = to_str_with_prec<2> (periods);
@@ -2381,7 +2425,7 @@ loan_get_formula_internal( LoanAssistantData *ldd, GString *gstr, const gchar *t
// for gnucash. So I stuck with bl::format, which is.
auto formula = (bl::format (tpl) % period_rate_str %
period_base_str % periods_str % principal_str).str();
- g_string_append (gstr, formula.c_str());
+ g_string_append (gstr, formula.c_str());
}
static
Summary of changes:
gnucash/gnome/assistant-loan.cpp | 48 ++++++++++++++++++++++++++++--
libgnucash/core-utils/gnc-locale-utils.cpp | 9 ++++--
2 files changed, 52 insertions(+), 5 deletions(-)
More information about the gnucash-changes
mailing list