From 91c2da56b561ee28793a1e0c72236e3910d8dea5 2017-09-27 13:05:36 From: Alexandre Leroux Date: 2017-09-27 13:05:36 Subject: [PATCH] Changes how to handle comment lines in file Some comment lines do not have '#', so we now consider comments to end when the header of the data has been reached --- diff --git a/plugins/amda/src/AmdaResultParser.cpp b/plugins/amda/src/AmdaResultParser.cpp index 586363b..df2fc2c 100644 --- a/plugins/amda/src/AmdaResultParser.cpp +++ b/plugins/amda/src/AmdaResultParser.cpp @@ -23,6 +23,10 @@ const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); /// Separator between values in a result line const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")}; +/// Regex to find the header of the data in the file. This header indicates the end of comments in +/// the file +const auto DATA_HEADER_REGEX = QRegularExpression{QStringLiteral("#\\s*DATA\\s*:")}; + /// Regex to find unit in a line. Examples of valid lines: /// ... PARAMETER_UNITS : nT ... /// ... PARAMETER_UNITS:nT ... @@ -75,8 +79,8 @@ Unit readXAxisUnit(QTextStream &stream) { QString line{}; - // Searches unit in the comment lines - while (stream.readLineInto(&line) && isCommentLine(line)) { + // Searches unit in the comment lines (as long as the reading has not reached the data header) + while (stream.readLineInto(&line) && !line.contains(DATA_HEADER_REGEX)) { auto match = UNIT_REGEX.match(line); if (match.hasMatch()) { return Unit{match.captured(1), true}; @@ -186,7 +190,6 @@ std::shared_ptr AmdaResultParser::readTxt(const QString &filePath, auto xAxisUnit = readXAxisUnit(stream); // Reads results - stream.seek(0); // returns to the beginning of the file auto results = readResults(stream, valueType); // Creates data series