From: vsr Date: Mon, 10 Feb 2020 15:01:08 +0000 (+0300) Subject: Locale management: improve localization helper (fix problems detected withing bos... X-Git-Tag: V9_5_0a1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=47d24bc0b4cc6efbc2229a3d03984e22ed02ea9a;p=modules%2Fkernel.git Locale management: improve localization helper (fix problems detected withing bos #18621) --- diff --git a/src/Basics/Basics_Utils.cxx b/src/Basics/Basics_Utils.cxx index 1896cd796..88c24cf07 100644 --- a/src/Basics/Basics_Utils.cxx +++ b/src/Basics/Basics_Utils.cxx @@ -83,13 +83,24 @@ namespace Kernel_Utils Localizer::Localizer() { - myCurLocale = setlocale(LC_NUMERIC, 0); - setlocale(LC_NUMERIC, "C"); + init(LC_NUMERIC, "C"); + } + + Localizer::Localizer(int category, const char* locale) + { + init(category, locale); + } + + void Localizer::init(int category, const char* locale) + { + myCategory = category; + myOriginalLocale = setlocale(category, NULL); + setlocale(category, locale); } Localizer::~Localizer() { - setlocale(LC_NUMERIC, myCurLocale.c_str()); + setlocale(myCategory, myOriginalLocale.c_str()); } std::string GetGUID( GUIDtype type ) @@ -108,7 +119,7 @@ namespace Kernel_Utils const wchar_t* decode(const char* encoded) { - //setlocale(LC_ALL, ""); + Localizer loc(LC_CTYPE, ""); size_t length = strlen(encoded) + sizeof(char); wchar_t* decoded = new wchar_t[length]; memset( decoded, '\0', length); @@ -123,7 +134,7 @@ namespace Kernel_Utils const char* encode(const wchar_t* decoded) { - //setlocale(LC_ALL, ""); + Localizer loc(LC_CTYPE, ""); size_t length = std::wcslen(decoded) + sizeof(wchar_t); char* encoded = new char[length]; memset( encoded, '\0', length); diff --git a/src/Basics/Basics_Utils.hxx b/src/Basics/Basics_Utils.hxx index ddb351d3b..4920a7dda 100644 --- a/src/Basics/Basics_Utils.hxx +++ b/src/Basics/Basics_Utils.hxx @@ -45,9 +45,13 @@ namespace Kernel_Utils { public: Localizer(); + Localizer(int, const char*); ~Localizer(); private: - std::string myCurLocale; + void init(int, const char*); + private: + int myCategory; + std::string myOriginalLocale; }; //! GUID type