From 94a8b0590f01c4a270e00b1713303b929390cf1c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 11 Apr 2023 13:11:05 -0600 Subject: [PATCH] More gracefully deal with Windoze line endings. --- source/grid/grid_in.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; -- 2.39.5