diff --git a/common/src/util.cpp b/common/src/util.cpp index f5717be08bcd3ecb4aa4cdd39fe7f6b6ad97d7b9..a30e4a37d3dcce3cb221ce9666ba5f2654a5d71e 100644 --- a/common/src/util.cpp +++ b/common/src/util.cpp @@ -376,6 +376,7 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename char lineBuffer[100000]; bool inputHasBeenRead = false; + std::string mcdLine; sentences.emplace_back(); while (!std::feof(file)) @@ -383,9 +384,12 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename if (lineBuffer != std::fgets(lineBuffer, 100000, file)) break; - std::string_view line(lineBuffer); + std::string line(lineBuffer); sentences.back().emplace_back(line); + if (line.back() == '\n') + line.pop_back(); + if (line.size() < 3) { if (!inputHasBeenRead) @@ -395,6 +399,12 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename continue; } + if (util::doIfNameMatch(std::regex("(?:(?:\\s|\\t)*)#(?:(?:\\s|\\t)*)global.columns(?:(?:\\s|\\t)*)=(?:(?:\\s|\\t)*)(.+)"), line, [&mcdLine, &line](const auto &) + { + mcdLine = line; + })) + continue; + inputHasBeenRead = true; } @@ -402,6 +412,10 @@ std::vector<std::vector<std::string>> util::readTSV(std::string_view tsvFilename sentences.pop_back(); std::fclose(file); + + if (not mcdLine.empty()) + for (auto & sentence : sentences) + sentence.insert(sentence.begin(), mcdLine); return sentences; }