Skip to content
Snippets Groups Projects
Commit 4398be6b authored by Ben Cumming's avatar Ben Cumming Committed by GitHub
Browse files

Merge pull request #36 from eth-cscs/bug/issue_34

Add save_getline with windows EOL support
parents 7f0a2564 a0b9b703
No related branches found
No related tags found
No related merge requests found
......@@ -129,9 +129,14 @@ std::istream &swc_parser::parse_record(std::istream &is, swc_record &record)
while (!is.eof() && !is.bad()) {
// consume empty and comment lines first
std::getline(is, linebuff_);
++lineno_;
if (!linebuff_.empty() && !starts_with(linebuff_, comment_prefix_))
if (!linebuff_.empty() &&
!starts_with(linebuff_, comment_prefix_) &&
!starts_with(linebuff_, "\r"))
{
break;
}
}
if (is.bad()) {
......
......@@ -212,6 +212,7 @@ public:
std::istream &parse_record(std::istream &is, swc_record &record);
private:
// Read the record from a string stream; will be treated like a single line
swc_record parse_record(std::istringstream &is);
......
......@@ -521,3 +521,35 @@ TEST(swc_parser, from_file_ball_and_stick)
EXPECT_TRUE(nest::mc::cell_basic_equality(local_cell, cell));
}
// check that windows EOL are supported in linux.
// This test is based on the ball_and_stick.swc with windows endings inserted
// manually in a file stream, regression test for issue_34
TEST(swc_parser, windows_eol)
{
// Check valid usage
std::stringstream is;
is << "# ball and stick model with\r\n";
is << "# - soma with radius 12.6157 2\r\n";
is << "# - dendrite with length 200 and radius 0.5\r\n";
is << "\r\n"; // parser stubles over empty line with \r\n
is << "1 1 0.0 0.0 0.0 6.30785 -1\r\n";
is << "2 2 6.30785 0.0 0.0 0.5 1\r\n";
is << "3 2 206.30785 0.0 0.0 0.5 2\r\n";
is << "\n";
// read the file into a cell object
auto cell = nest::mc::io::swc_read_cell(is);
// verify that the correct number of nodes was read
EXPECT_EQ(cell.num_segments(), 2);
EXPECT_EQ(cell.num_compartments(), 2u);
// make an equivalent cell via C++ interface
nest::mc::cell local_cell;
local_cell.add_soma(6.30785);
local_cell.add_cable(0, nest::mc::segmentKind::dendrite, 0.5, 0.5, 200);
EXPECT_TRUE(nest::mc::cell_basic_equality(local_cell, cell));
}
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