Commit 312e679b authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Kitware Robot
Browse files

Merge topic '17242_handle_windows_line_endings'

1798908e Remove '\r' from `vtkDataReader::ReadLine`.
8fc8cbab

 Handle '\r' in vtkDataReader.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: default avatarDavid Lonie <david.lonie@kitware.com>
Merge-request: !2548
parents 81a718e4 1798908e
Pipeline #48551 failed with stage
in 0 seconds
......@@ -36,6 +36,8 @@
#include "vtkInformationStringVectorKey.h"
#include "vtkInformationUnsignedLongKey.h"
#include <vtksys/SystemTools.hxx>
namespace {
static vtkInformationDoubleKey *TestDoubleKey =
......@@ -200,7 +202,7 @@ int TestLegacyArrayMetaData(int argc, char *argv[])
testWriter->WriteToOutputStringOn();
testReader->ReadFromInputStringOn();
// Test ASCII mode:
// Test ASCII mode: (string).
testWriter->SetFileTypeToASCII();
if (!testWriter->Write())
{
......@@ -220,7 +222,7 @@ int TestLegacyArrayMetaData(int argc, char *argv[])
return EXIT_FAILURE;
}
// Test binary mode:
// Test binary mode: (string)
testWriter->SetFileTypeToBinary();
if (!testWriter->Write())
{
......@@ -240,5 +242,56 @@ int TestLegacyArrayMetaData(int argc, char *argv[])
return EXIT_FAILURE;
}
if (!testing->GetTempDirectory())
{
std::cout << "No temporary directory specified. Skipping testing read/write from files."
<< std::endl;
return EXIT_SUCCESS;
}
const std::string temp = testing->GetTempDirectory();
const std::string tfilename = temp + "/TestLegacyArrayMetaData.vtk";
testWriter->WriteToOutputStringOff();
testWriter->SetFileName(tfilename.c_str());
testReader->ReadFromInputStringOff();
testReader->SetFileName(tfilename.c_str());
vtksys::SystemTools::RemoveFile(tfilename);
// Test ASCII mode: (file).
testWriter->SetFileTypeToASCII();
if (!testWriter->Write())
{
std::cerr << "Write to file (ASCII) failed!" << std::endl;
return EXIT_FAILURE;
}
testReader->Update();
grid = testReader->GetOutput();
if (!verify(grid))
{
std::cerr << "ASCII mode test (file i/o) failed.\n";
return EXIT_FAILURE;
}
// Test binary mode: (file)
vtksys::SystemTools::RemoveFile(tfilename);
testWriter->SetFileTypeToBinary();
if (!testWriter->Write())
{
std::cerr << "Write to file (binary) failed!" << std::endl;
return EXIT_FAILURE;
}
testReader->Update();
grid = testReader->GetOutput();
if (!verify(grid))
{
std::cerr << "Binary mode test (file i/o) failed.\n";
return EXIT_FAILURE;
}
vtksys::SystemTools::RemoveFile(tfilename);
return EXIT_SUCCESS;
}
......@@ -221,6 +221,12 @@ int vtkDataReader::ReadLine(char result[256])
this->IS->ignore(VTK_INT_MAX, '\n');
}
}
// remove '\r', if present.
size_t slen = strlen(result);
if (slen > 0 && result[slen-1] == '\r')
{
result[slen-1] = '\0';
}
return 1;
}
......@@ -1960,6 +1966,8 @@ vtkAbstractArray *vtkDataReader::ReadArray(const char *dataType, int numTuples,
{
case ' ':
continue;
case '\r':
continue;
case '\n':
// pop line, peek at next
if (!this->ReadLine(line))
......
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