Salome HOME
Fix problems with localization: prevent accidental breaking of application locale
authorvsr <vsr@opencascade.com>
Wed, 12 Feb 2020 11:47:13 +0000 (14:47 +0300)
committervsr <vsr@opencascade.com>
Wed, 12 Feb 2020 11:47:38 +0000 (14:47 +0300)
src/MEDLoader/SauvMedConvertor.cxx
src/MEDLoader/SauvReader.cxx
src/MEDLoader/SauvUtilities.hxx

index ad9e3511817b3415c70b46b84a0e92e212f9e92d..47be7295689215a027f93f5b9b16c98071ba2a60 100644 (file)
@@ -1819,7 +1819,6 @@ void ASCIIReader::init( int nbToRead, int nbPosInLine, int width, int shift /*=
     {
       _curPos = 0;
     }
-  _curLocale.clear();
 }
 
 //================================================================================
@@ -1852,11 +1851,7 @@ void ASCIIReader::initIntReading(int nbValues)
 
 void ASCIIReader::initDoubleReading(int nbValues)
 {
-  init( nbValues, 3, 22 );
-
-  // Correction 2 of getDouble(): set "C" numeric locale to read numbers
-  // with dot decimal point separator, as it is in SAUVE files
-  _curLocale = setlocale(LC_NUMERIC, "C");
+  init( nbValues, 3, 22 ); 
 }
 
 //================================================================================
@@ -1903,11 +1898,6 @@ void ASCIIReader::next()
   else
     {
       _curPos = 0;
-      if ( !_curLocale.empty() )
-        {
-          setlocale(LC_NUMERIC, _curLocale.c_str());
-          _curLocale.clear();
-        }
     }
 }
 
index 931d35255e85cbfe3731da16330b557450a710b1..3640d4a4da6f4bba13aaf777ebd9e2f5345bd649 100644 (file)
@@ -38,6 +38,24 @@ using namespace std;
 
 #define GIBI_EQUAL(var_str, stat_str) (strncmp (var_str, stat_str, strlen(stat_str)) == 0)
 
+namespace
+{
+  class Localizer
+  {
+    std::string _locale;
+  public:
+    Localizer()
+    {
+      _locale = setlocale(LC_NUMERIC, NULL);
+      setlocale(LC_NUMERIC, "C");
+    }
+    ~Localizer()
+    {
+      setlocale(LC_NUMERIC, _locale.c_str());
+    }
+  };
+}
+
 //================================================================================
 /*!
  * \brief Creates a reader of a given sauve file
@@ -114,6 +132,8 @@ std::string SauvReader::lineNb() const
 
 MEDCoupling::MEDFileData * SauvReader::loadInMEDFileDS()
 {
+  Localizer loc; // localization, to read numbers in "C" locale
+
   SauvUtilities::IntermediateMED iMed; // intermadiate DS
   _iMed = &iMed;
 
index f10e2f8a1c5b328d3896c7c36dab4632492ff886..2150df37bd1878b311d4d79667cab6296040e2e7 100644 (file)
@@ -113,7 +113,7 @@ namespace SauvUtilities
     std::size_t getHeapMemorySizeWithoutChildren() const { return 0; }
     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const { return std::vector<const BigMemoryObject *>(); }
   protected:
-    std::string _fileName, _curLocale;
+    std::string _fileName;
     int _iRead, _nbToRead;
   };
 }