Commit a1fa3274 authored by Marco Amagliani's avatar Marco Amagliani
Browse files

Fixes the LocaleSession in such a way to restore the C locale even if the...

Fixes the LocaleSession in such a way to restore the C locale even if the global C++ locale does not have a named. It fixes REFORM-388 and test locale_001.cc.
parent bee7a7fd
......@@ -35,6 +35,10 @@ bool variable(const char* const _vrbl_name, std::string& _vrbl)
//default session locale is "C" (i.e., "." is the decimal point)
LocaleSession::LocaleSession(const char* const _ssn_lcle)
{
c_lcl_bckp_ = ::setlocale(LC_ALL, NULL);
// std::locale::global set the C++ and C locale at the same time
// only if the locale has a name (as in the following call).
// See http://www.cplusplus.com/reference/locale/locale/global/
lcl_bckp_ = std::locale::global(std::locale(_ssn_lcle));
DEB_only(char* lcle = )::setlocale(LC_ALL, NULL);
DEB_error_if(lcle == NULL,
......@@ -47,6 +51,9 @@ LocaleSession::LocaleSession(const char* const _ssn_lcle)
LocaleSession::~LocaleSession()
{
std::locale::global(lcl_bckp_);
// We can not be sure that lcl_bckp_ had a name, so we must reset the
// C locale explicitly.
::setlocale(LC_ALL, c_lcl_bckp_.c_str());
}
std::string time()
......
......@@ -47,6 +47,7 @@ public:
private:
std::locale lcl_bckp_;
std::string c_lcl_bckp_;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment