diff --git a/src/swcio.cpp b/src/swcio.cpp index f1a272df2fb583331e3695964a0416d15868e327..05cb61170221f3fc715ddef7c8271606c1f359d9 100644 --- a/src/swcio.cpp +++ b/src/swcio.cpp @@ -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()) { diff --git a/src/swcio.hpp b/src/swcio.hpp index 70f979cda362f503a81965c274a5cdeb23ea5056..4b6457123e062c65a2091853bc3e581e3c1eb8e7 100644 --- a/src/swcio.hpp +++ b/src/swcio.hpp @@ -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); diff --git a/tests/test_swcio.cpp b/tests/test_swcio.cpp index 5ba0b991a865dfb397e5c1dbbb1e8813e71b628c..0ebe9c84b06ff7c22db289ebcb79c21eb50239d4 100644 --- a/tests/test_swcio.cpp +++ b/tests/test_swcio.cpp @@ -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)); +}