Commit d304a797 authored by Joachim Pouderoux's avatar Joachim Pouderoux Committed by Kitware Robot

Merge topic 'FixLocaleForLegacyWriters2'

e4f5ae84 Fix locale issue with Legacy VTK readers & writers
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !5136
parents f3f6518d e4f5ae84
......@@ -58,8 +58,8 @@
#include <vtksys/SystemTools.hxx>
#include <sstream>
#include <cctype>
#include <sstream>
// I need a safe way to read a line of arbitrary length. It exists on
// some platforms but not others so I'm afraid I have to write it
......@@ -447,6 +447,10 @@ size_t vtkDataReader::Peek(char *str, size_t n)
// Open a vtk data file. Returns zero if error.
int vtkDataReader::OpenVTKFile(const char* fname)
{
// Save current locale settings and set standard one to
// avoid locale issues - for instance with the decimal separator.
this->CurrentLocale = std::locale::global(std::locale::classic());
if(!fname && this->GetNumberOfFileNames() >0)
{
fname = this->GetFileName(0);
......@@ -3417,6 +3421,10 @@ char *vtkDataReader::LowerCase(char *str, const size_t len)
void vtkDataReader::CloseVTKFile()
{
vtkDebugMacro(<<"Closing vtk file");
// Restore the previous locale settings
std::locale::global(this->CurrentLocale);
delete this->IS;
this->IS = nullptr;
}
......
......@@ -33,6 +33,8 @@
#include "vtkSimpleReader.h"
#include "vtkStdString.h" // For API using strings
#include <locale> // For locale settings
#define VTK_ASCII 1
#define VTK_BINARY 2
......@@ -554,6 +556,8 @@ protected:
int FileMajorVersion;
int FileMinorVersion;
std::locale CurrentLocale;
void InitializeCharacteristics();
int CharacterizeFile(); //read entire file, storing important characteristics
void CheckFor(const char* name, char *line, int &num, char** &array,
......
......@@ -127,6 +127,10 @@ vtkDataWriter::~vtkDataWriter()
// Open a vtk data file. Returns nullptr if error.
ostream *vtkDataWriter::OpenVTKFile()
{
// Save current locale settings and set standard one to
// avoid locale issues - for instance with the decimal separator.
this->CurrentLocale = std::locale::global(std::locale::classic());
ostream *fptr;
if ((!this->WriteToOutputString) && ( !this->FileName ))
......@@ -2229,6 +2233,9 @@ void vtkDataWriter::CloseVTKFile(ostream *fp)
{
vtkDebugMacro(<<"Closing vtk file\n");
// Restore the previous locale settings
std::locale::global(this->CurrentLocale);
if ( fp != nullptr )
{
if (this->WriteToOutputString)
......
......@@ -32,6 +32,8 @@
#include "vtkIOLegacyModule.h" // For export macro
#include "vtkWriter.h"
#include <locale> // For locale settings
class vtkCellArray;
class vtkDataArray;
class vtkDataSet;
......@@ -315,6 +317,8 @@ protected:
char* PedigreeIdsName;
char* EdgeFlagsName;
std::locale CurrentLocale;
int WriteArray(ostream *fp, int dataType, vtkAbstractArray *data, const char *format,
vtkIdType num, vtkIdType numComp);
int WriteScalarData(ostream *fp, vtkDataArray *s, vtkIdType num);
......
Markdown is supported
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