From 0b352bf318507d74c5c325970a129213693c660b Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sun, 25 Aug 2019 10:43:20 +0200 Subject: [PATCH] fix do not write outfiles with head line only --- csv2xlslib/OutputDoc.cpp | 12 +++--------- csv2xlslib/OutputDoc.hpp | 4 ++-- csv2xlslib/parseCsvFile.cpp | 10 ++++++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/csv2xlslib/OutputDoc.cpp b/csv2xlslib/OutputDoc.cpp index 8e3e689..9ffe599 100644 --- a/csv2xlslib/OutputDoc.cpp +++ b/csv2xlslib/OutputDoc.cpp @@ -10,12 +10,6 @@ Row OutputDoc::RowAfterClearSheet() self_->clearSheet(); m_column = Column(0); m_row = Row(0); - if (m_headline.size()) - { - for(auto const& column : m_headline ) - appendCell(CellContent(column.c_str(), column.size())); - newLine(); - } return m_row; } @@ -25,14 +19,14 @@ int OutputDoc::writeInto(OutputFileName const& out_put_file, FileNumber file_num return 0; return self_->writeInto(out_put_file, file_number); } -void OutputDoc::setHeadLine(HeadLineType const& head_line) +void OutputDoc::set(InputHasHeadLine input_has_head_line) { - m_headline = head_line; + m_input_has_head_line = input_has_head_line; } bool OutputDoc::isEmpty()const { - return (m_headline.size()) + return (m_input_has_head_line.Get()) ? (m_row == Row(1))&&(m_column == Column(0)) : (m_row == Row(0))&&(m_column == Column(0)); } diff --git a/csv2xlslib/OutputDoc.hpp b/csv2xlslib/OutputDoc.hpp index 88f6e90..aaa226c 100644 --- a/csv2xlslib/OutputDoc.hpp +++ b/csv2xlslib/OutputDoc.hpp @@ -27,7 +27,7 @@ class OutputDoc Row RowAfterClearSheet(); int writeInto(OutputFileName const& out_put_file, FileNumber file_number)const; - void setHeadLine(HeadLineType const& head_line); + void set(InputHasHeadLine input_has_head_line); Column appendCell(CellContent cell_content); Row newLine(); bool isEmpty()const; @@ -78,7 +78,7 @@ class OutputDoc Row m_row = Row(0); Column m_column = Column(0); std::optional output_column_limit; - HeadLineType m_headline; + InputHasHeadLine m_input_has_head_line; }; } diff --git a/csv2xlslib/parseCsvFile.cpp b/csv2xlslib/parseCsvFile.cpp index c4dbd77..197be15 100644 --- a/csv2xlslib/parseCsvFile.cpp +++ b/csv2xlslib/parseCsvFile.cpp @@ -29,10 +29,12 @@ namespace csv2xls std::stringstream csv_input(headline); auto buffer = Buffer(parameter_.input_buffer_size); - return (parameter_.input_has_head_line.Get()) - ?convertCsv(buffer, parameter_, csv_input, std::move(output_doc)) - :std::optional(std::move(output_doc)); -// return output_doc; + if(parameter_.input_has_head_line.Get()) + { + output_doc.set(parameter_.input_has_head_line); + return convertCsv(buffer, parameter_, csv_input, std::move(output_doc)); + } + return std::optional(std::move(output_doc)); }; } auto makeOutputDoc=[](auto file_gen ) {