From: Wolfgang Bangerth Date: Tue, 11 Apr 2023 19:11:05 +0000 (-0600) Subject: More gracefully deal with Windoze line endings. X-Git-Tag: v9.5.0-rc1~305^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94a8b0590f01c4a270e00b1713303b929390cf1c;p=dealii.git More gracefully deal with Windoze line endings. --- diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 6bd7b24f9e..03a3ae8208 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -1465,6 +1465,15 @@ GridIn::read_comsol_mphtxt(std::istream &in) std::string line; std::getline(in, line); + // We tend to get these sorts of files from folks who run on + // Windows and where line endings are \r\n instead of just + // \n. The \r is redundant unless you still use a line printer, + // so get rid of it in order to not confuse any of the functions + // below that try to interpret the entire content of a line + // as a string: + if ((line.size() > 0) && (line.back() == '\r')) + line.erase(line.size() - 1); + // Strip trailing comments, then strip whatever spaces are at the end // of the line, and if anything is left, concatenate that to the previous // content of the file: @@ -1549,7 +1558,8 @@ GridIn::read_comsol_mphtxt(std::istream &in) while (whole_file.peek() == '\n') whole_file.get(); std::getline(whole_file, s); - AssertThrow(s == "4 Mesh", ExcNotImplemented()); + AssertThrow(s == "4 Mesh", + ExcMessage("Expected '4 Mesh', but got '" + s + "'.")); } { unsigned int version;