Line data Source code
1 : /* Copyright (C) 2025 Robert Schiwon 2 : * 3 : * This file is part of libjdx. 4 : * 5 : * libjdx is free software: you can redistribute it and/or modify it under the 6 : * terms of the GNU Lesser General Public License as published by the Free 7 : * Software Foundation, either version 3 of the License, or (at your option) any 8 : * later version. 9 : * 10 : * libjdx is distributed in the hope that it will be useful, but WITHOUT ANY 11 : * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 : * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 13 : * details. 14 : * 15 : * You should have received a copy of the GNU Lesser General Public License 16 : * along with libjdx. If not, see <https://www.gnu.org/licenses/>. 17 : */ 18 : #include "jdx/TabularData.hpp" 19 : #include "util/LdrUtils.hpp" 20 : #include "util/PeakAssignmentsParser.hpp" 21 : #include "util/StringUtils.hpp" 22 : 23 82 : libjdx::jdx::TabularData::TabularData( 24 82 : std::string label, std::string variableList, io::TextReader& reader) 25 82 : : DataLdr(std::move(label), std::move(variableList), reader) 26 : { 27 82 : } 28 : 29 7 : std::optional<std::string> libjdx::jdx::TabularData::getWidthFunction() 30 : { 31 : auto appendToDescription 32 7 : = [](std::string comment, std::string& description) { 33 7 : if (!description.empty()) 34 : { 35 2 : description += '\n'; 36 : } 37 7 : util::trim(comment); 38 7 : description.append(comment); 39 7 : }; 40 : 41 14 : auto getCommentLines = [this, &appendToDescription]() { 42 : // comment $$ in line(s) following LDR start may contain peak function 43 7 : auto& reader = getReader(); 44 7 : auto readerPos = reader.tellg(); 45 14 : std::string line{}; 46 14 : std::string functionDescription{}; 47 35 : while (!reader.eof() && !util::isLdrStart(line = reader.readLine()) 48 42 : && util::isPureComment(line)) 49 : { 50 7 : readerPos = reader.tellg(); 51 7 : auto comment = util::stripLineComment(line).second; 52 7 : appendToDescription(comment.value(), functionDescription); 53 : } 54 : // reset reader position to start of first assignment or start of next 55 : // LDR 56 7 : reader.seekg(readerPos); 57 : // return 58 7 : return functionDescription.empty() 59 : ? std::nullopt 60 14 : : std::optional<std::string>{functionDescription}; 61 7 : }; 62 : 63 7 : return callAndResetStreamPos<std::optional<std::string>>(getCommentLines); 64 : }