From: Arvin Schnell Date: Thu, 3 Sep 2020 08:50:57 +0000 (+0200) Subject: - some cleanup in formatters classes X-Git-Tag: v0.8.14~26^2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=bf5a9ecfcff5edda5bca194d1b2115fb8cfefe7c;p=thirdparty%2Fsnapper.git - some cleanup in formatters classes --- diff --git a/client/Command/GetConfig/ConfigData/Csv.cc b/client/Command/GetConfig/ConfigData/Csv.cc index a31bd37b..70808b31 100644 --- a/client/Command/GetConfig/ConfigData/Csv.cc +++ b/client/Command/GetConfig/ConfigData/Csv.cc @@ -64,7 +64,7 @@ namespace snapper CsvFormatter formatter(columns, rows, _separator); - return formatter.output(); + return formatter.str(); } } diff --git a/client/Command/GetConfig/ConfigData/Json.cc b/client/Command/GetConfig/ConfigData/Json.cc index 823d11a6..ce8dde48 100644 --- a/client/Command/GetConfig/ConfigData/Json.cc +++ b/client/Command/GetConfig/ConfigData/Json.cc @@ -38,7 +38,7 @@ namespace snapper JsonFormatter formatter(data); - return formatter.output(); + return formatter.str(); } } diff --git a/client/Command/GetConfig/ConfigData/Table.cc b/client/Command/GetConfig/ConfigData/Table.cc index 00e62d61..49671bab 100644 --- a/client/Command/GetConfig/ConfigData/Table.cc +++ b/client/Command/GetConfig/ConfigData/Table.cc @@ -32,7 +32,7 @@ namespace snapper { Command::GetConfig::ConfigData::Table::Table( - const Command::GetConfig& command, TableLineStyle style) : + const Command::GetConfig& command, TableStyle style) : ConfigData(command), _style(style) {} @@ -63,7 +63,7 @@ namespace snapper TableFormatter formatter(columns, rows, _style); - return formatter.output(); + return formatter.str(); } diff --git a/client/Command/GetConfig/ConfigData/Table.h b/client/Command/GetConfig/ConfigData/Table.h index a50fc46e..ec82cef2 100644 --- a/client/Command/GetConfig/ConfigData/Table.h +++ b/client/Command/GetConfig/ConfigData/Table.h @@ -37,7 +37,7 @@ namespace snapper public: - Table(const GetConfig& command, TableLineStyle style); + Table(const GetConfig& command, TableStyle style); virtual std::string output() const override; @@ -45,7 +45,7 @@ namespace snapper std::string label_for(const string& column) const; - TableLineStyle _style; + TableStyle _style; }; diff --git a/client/Command/ListConfigs/SnappersData/Csv.cc b/client/Command/ListConfigs/SnappersData/Csv.cc index 5bd96374..e11d22be 100644 --- a/client/Command/ListConfigs/SnappersData/Csv.cc +++ b/client/Command/ListConfigs/SnappersData/Csv.cc @@ -59,7 +59,7 @@ namespace snapper CsvFormatter formatter(columns, rows, _separator); - return formatter.output(); + return formatter.str(); } } diff --git a/client/Command/ListConfigs/SnappersData/Json.cc b/client/Command/ListConfigs/SnappersData/Json.cc index 8206c0f6..8da87e13 100644 --- a/client/Command/ListConfigs/SnappersData/Json.cc +++ b/client/Command/ListConfigs/SnappersData/Json.cc @@ -48,7 +48,7 @@ namespace snapper formatter.skip_format_values({ SNAPPERS_KEY }); - return formatter.output(); + return formatter.str(); } @@ -64,7 +64,7 @@ namespace snapper JsonFormatter::List json_list(data); - return json_list.output(1); + return json_list.str(1); } @@ -77,7 +77,7 @@ namespace snapper JsonFormatter formatter(data); - return formatter.output(2); + return formatter.str(2); } } diff --git a/client/Command/ListConfigs/SnappersData/Table.cc b/client/Command/ListConfigs/SnappersData/Table.cc index 62f097b2..b2f4496e 100644 --- a/client/Command/ListConfigs/SnappersData/Table.cc +++ b/client/Command/ListConfigs/SnappersData/Table.cc @@ -32,7 +32,7 @@ namespace snapper { Command::ListConfigs::SnappersData::Table::Table( - const Command::ListConfigs& command, TableLineStyle style) : + const Command::ListConfigs& command, TableStyle style) : SnappersData(command), _style(style) {} @@ -58,7 +58,7 @@ namespace snapper TableFormatter formatter(columns, rows, _style); - return formatter.output(); + return formatter.str(); } diff --git a/client/Command/ListConfigs/SnappersData/Table.h b/client/Command/ListConfigs/SnappersData/Table.h index 13d2aeea..cf51fa10 100644 --- a/client/Command/ListConfigs/SnappersData/Table.h +++ b/client/Command/ListConfigs/SnappersData/Table.h @@ -37,7 +37,7 @@ namespace snapper public: - Table(const ListConfigs& command, TableLineStyle style); + Table(const ListConfigs& command, TableStyle style); virtual std::string output() const override; @@ -45,7 +45,7 @@ namespace snapper std::string label_for(const std::string& column) const; - TableLineStyle _style; + TableStyle _style; }; diff --git a/client/Command/ListSnapshots/SnappersData/Csv.cc b/client/Command/ListSnapshots/SnappersData/Csv.cc index 9be1ba62..d9634e16 100644 --- a/client/Command/ListSnapshots/SnappersData/Csv.cc +++ b/client/Command/ListSnapshots/SnappersData/Csv.cc @@ -55,7 +55,7 @@ namespace snapper CsvFormatter formatter(columns, rows, _separator); - return formatter.output(); + return formatter.str(); } diff --git a/client/Command/ListSnapshots/SnappersData/Json.cc b/client/Command/ListSnapshots/SnappersData/Json.cc index b6244900..7804c861 100644 --- a/client/Command/ListSnapshots/SnappersData/Json.cc +++ b/client/Command/ListSnapshots/SnappersData/Json.cc @@ -49,7 +49,7 @@ namespace snapper formatter.set_inline(true); - return formatter.output(3); + return formatter.str(3); } } @@ -72,7 +72,7 @@ namespace snapper formatter.skip_format_values(keys); - return formatter.output(); + return formatter.str(); } @@ -118,12 +118,12 @@ namespace snapper formatter.skip_format_values(skip_format); - data.push_back(formatter.output(2)); + data.push_back(formatter.str(2)); } JsonFormatter::List json_list(data); - return json_list.output(1); + return json_list.str(1); } diff --git a/client/Command/ListSnapshots/SnappersData/Table.cc b/client/Command/ListSnapshots/SnappersData/Table.cc index d88dbdc8..7238af61 100644 --- a/client/Command/ListSnapshots/SnappersData/Table.cc +++ b/client/Command/ListSnapshots/SnappersData/Table.cc @@ -36,7 +36,7 @@ namespace snapper { Command::ListSnapshots::SnappersData::Table::Table( - const Command::ListSnapshots& command, TableLineStyle style) : + const Command::ListSnapshots& command, TableStyle style) : SnappersData(command), _style(style) {} @@ -178,7 +178,7 @@ namespace snapper TableFormatter formatter(columns, rows, _style); - return formatter.output(); + return formatter.str(); } diff --git a/client/Command/ListSnapshots/SnappersData/Table.h b/client/Command/ListSnapshots/SnappersData/Table.h index b32d3ce7..397a6ca7 100644 --- a/client/Command/ListSnapshots/SnappersData/Table.h +++ b/client/Command/ListSnapshots/SnappersData/Table.h @@ -37,7 +37,7 @@ namespace snapper public: - Table(const ListSnapshots& command, TableLineStyle style); + Table(const ListSnapshots& command, TableStyle style); virtual std::string output() const override; @@ -58,7 +58,7 @@ namespace snapper TableAlign column_alignment(const string& column) const; - TableLineStyle _style; + TableStyle _style; }; diff --git a/client/GlobalOptions.cc b/client/GlobalOptions.cc index 703b5be3..0e5aae66 100644 --- a/client/GlobalOptions.cc +++ b/client/GlobalOptions.cc @@ -107,12 +107,12 @@ namespace snapper } - TableLineStyle + TableStyle GlobalOptions::table_style_value(const ParsedOpts& opts) const { ParsedOpts::const_iterator it = opts.find("table-style"); if (it == opts.end()) - return cli::TableFormatter::default_style(); + return cli::TableFormatter::default_style; string str = it->second; @@ -123,7 +123,7 @@ namespace snapper if (value >= Table::numStyles) throw exception(); - return (TableLineStyle)(value); + return (TableStyle)(value); } catch (const exception&) { @@ -133,7 +133,7 @@ namespace snapper SN_THROW(OptionsException(error)); } - return cli::TableFormatter::default_style(); + return cli::TableFormatter::default_style; } @@ -171,7 +171,7 @@ namespace snapper { ParsedOpts::const_iterator it = opts.find("separator"); if (it == opts.end()) - return cli::CsvFormatter::default_separator(); + return cli::CsvFormatter::default_separator; return it->second; } diff --git a/client/GlobalOptions.h b/client/GlobalOptions.h index b4abff22..9c953dfd 100644 --- a/client/GlobalOptions.h +++ b/client/GlobalOptions.h @@ -52,7 +52,7 @@ namespace snapper bool no_dbus() const { return _no_dbus; } bool version() const { return _version; } bool help() const { return _help; } - TableLineStyle table_style() const { return _table_style; } + TableStyle table_style() const { return _table_style; } OutputFormat output_format() const { return _output_format; } string separator() const { return _separator; } string config() const { return _config; } @@ -65,7 +65,7 @@ namespace snapper void check_options(const ParsedOpts& parsed_opts) const; - TableLineStyle table_style_value(const ParsedOpts& parsed_opts) const; + TableStyle table_style_value(const ParsedOpts& parsed_opts) const; OutputFormat output_format_value(const ParsedOpts& parsed_opts) const; string separator_value(const ParsedOpts& parsed_opts) const; string config_value(const ParsedOpts& parsed_opts) const; @@ -79,7 +79,7 @@ namespace snapper bool _no_dbus; bool _version; bool _help; - TableLineStyle _table_style; + TableStyle _table_style; OutputFormat _output_format; string _separator; string _config; diff --git a/client/utils/CsvFormatter.cc b/client/utils/CsvFormatter.cc index b566b89f..860eda51 100644 --- a/client/utils/CsvFormatter.cc +++ b/client/utils/CsvFormatter.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] SUSE LLC + * Copyright (c) [2019-2020] SUSE LLC * * All Rights Reserved. * @@ -25,79 +25,47 @@ #include "client/utils/CsvFormatter.h" -using namespace std; namespace snapper { - namespace cli - { - - namespace - { - - const string DEFAULT_SEPARATOR = ","; - - - string double_quotes(const string value) - { - return boost::algorithm::replace_all_copy(value, "\"", "\"\"" ); - } - - - string enclose_with_quotes(const string value) - { - return "\"" + value + "\""; - } - - } + using namespace std; - const string CsvFormatter::default_separator() - { - return DEFAULT_SEPARATOR; - } - - - CsvFormatter::CsvFormatter( - vector columns, - vector> rows) : - _columns(columns), _rows(rows), _separator(default_separator()) - {} + namespace cli + { - CsvFormatter::CsvFormatter( - vector columns, - vector> rows, - const string separator) : - _columns(columns), _rows(rows), _separator(separator) - {} + const std::string CsvFormatter::default_separator = ","; - string CsvFormatter::output() const + string + CsvFormatter::str() const { string cvs_output; - cvs_output = csv_line(_columns); + cvs_output = csv_line(header); - for (auto row : _rows) + for (const vector& row : rows) cvs_output += csv_line(row); return cvs_output; } - string CsvFormatter::csv_line(vector values) const + string + CsvFormatter::csv_line(const vector& values) const { vector csv_values; - for (auto value : values) + for (const string& value : values) csv_values.push_back(csv_value(value)); - return boost::algorithm::join(csv_values, _separator) + "\n"; + return boost::algorithm::join(csv_values, separator) + "\n"; } - string CsvFormatter::csv_value(const string value) const + string + CsvFormatter::csv_value(const string& value) const { string fixed_value = boost::algorithm::trim_copy(value); @@ -108,11 +76,12 @@ namespace snapper } - bool CsvFormatter::has_special_chars(const string value) const + bool + CsvFormatter::has_special_chars(const string& value) const { - vector special_chars = { _separator, "\n", "\"" }; + vector special_chars = { separator, "\n", "\"" }; - for (auto special_char : special_chars) + for (const string& special_char : special_chars) { if (value.find(special_char) != string::npos) return true; @@ -121,5 +90,20 @@ namespace snapper return false; } + + string + CsvFormatter::double_quotes(const string& value) + { + return boost::algorithm::replace_all_copy(value, "\"", "\"\"" ); + } + + + string + CsvFormatter::enclose_with_quotes(const string& value) + { + return "\"" + value + "\""; + } + } -} \ No newline at end of file + +} diff --git a/client/utils/CsvFormatter.h b/client/utils/CsvFormatter.h index 24c8c327..363132d2 100644 --- a/client/utils/CsvFormatter.h +++ b/client/utils/CsvFormatter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] SUSE LLC + * Copyright (c) [2019-2020] SUSE LLC * * All Rights Reserved. * @@ -25,8 +25,13 @@ #include #include + namespace snapper { + + using namespace std; + + namespace cli { @@ -35,36 +40,36 @@ namespace snapper public: - static const std::string default_separator(); - - CsvFormatter( - std::vector columns, - std::vector> rows); + static const string default_separator; - CsvFormatter( - std::vector columns, - std::vector> rows, - const std::string separator); + CsvFormatter(const vector& header, const vector>& rows, + const string& separator) + : header(header), rows(rows), separator(separator) + { + } - std::string output() const; + string str() const; private: - std::string csv_line(std::vector values) const; + string csv_line(const vector& values) const; - std::string csv_value(const std::string value) const; + string csv_value(const string& value) const; - bool has_special_chars(const std::string value) const; + bool has_special_chars(const string& value) const; - std::vector _columns; + static string double_quotes(const string& value); - std::vector> _rows; + static string enclose_with_quotes(const string& value); - const std::string _separator; + const vector header; + const vector> rows; + const string separator; }; } + } #endif diff --git a/client/utils/JsonFormatter.cc b/client/utils/JsonFormatter.cc index ec2f7c66..b22bc9c2 100644 --- a/client/utils/JsonFormatter.cc +++ b/client/utils/JsonFormatter.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] SUSE LLC + * Copyright (c) [2019-2020] SUSE LLC * * All Rights Reserved. * @@ -22,62 +22,59 @@ #include #include #include -#include #include "client/utils/JsonFormatter.h" -using namespace std; namespace snapper { - namespace cli - { - namespace - { - - string indent(u_int indent_level) - { - return string(indent_level * 2, ' '); - } + using namespace std; - string escape(const string& value) - { - string fixed_value = value; + namespace cli + { - boost::algorithm::replace_all(fixed_value, "\\", "\\\\"); - boost::algorithm::replace_all(fixed_value, "\"", "\\\""); - boost::algorithm::replace_all(fixed_value, "\b", "\\b"); - boost::algorithm::replace_all(fixed_value, "\f", "\\f"); - boost::algorithm::replace_all(fixed_value, "\n", "\\n"); - boost::algorithm::replace_all(fixed_value, "\r", "\\r"); - boost::algorithm::replace_all(fixed_value, "\t", "\\t"); + string + JsonFormatter::indent(u_int indent_level) + { + return string(indent_level * 2, ' '); + } - return fixed_value; - } + string + JsonFormatter::escape(const string& value) + { + string fixed_value = value; - string quote(const string& value) - { - return "\"" + value + "\""; - } + boost::algorithm::replace_all(fixed_value, "\\", "\\\\"); + boost::algorithm::replace_all(fixed_value, "\"", "\\\""); + boost::algorithm::replace_all(fixed_value, "\b", "\\b"); + boost::algorithm::replace_all(fixed_value, "\f", "\\f"); + boost::algorithm::replace_all(fixed_value, "\n", "\\n"); + boost::algorithm::replace_all(fixed_value, "\r", "\\r"); + boost::algorithm::replace_all(fixed_value, "\t", "\\t"); + return fixed_value; + } - string to_json(const string& value) - { - return quote(escape(boost::algorithm::trim_copy(value))); - } + string + JsonFormatter::quote(const string& value) + { + return "\"" + value + "\""; } - JsonFormatter::JsonFormatter(const Data& data) : - _data(data), _inline(false) - {} + string + JsonFormatter::to_json(const string& value) + { + return quote(escape(boost::algorithm::trim_copy(value))); + } - string JsonFormatter::output(u_int indent_level) const + string + JsonFormatter::str(u_int indent_level) const { string first_indent = _inline ? "" : indent(indent_level); @@ -87,11 +84,12 @@ namespace snapper } - string JsonFormatter::json_attributes(u_int indent_level) const + string + JsonFormatter::json_attributes(u_int indent_level) const { vector attributes; - for (auto& data_pair : _data) + for (auto& data_pair : data) { string value = data_pair.second; @@ -105,28 +103,22 @@ namespace snapper } - bool JsonFormatter::skip_format_value(const string& key) const + bool + JsonFormatter::skip_format_value(const string& key) const { - auto it = find(_skip_format_values.begin(), _skip_format_values.end(), key); - - if (it != _skip_format_values.end()) - return true; - - return false; + return find(_skip_format_values.begin(), _skip_format_values.end(), key) != + _skip_format_values.end(); } - JsonFormatter::JsonFormatter::List::List(const vector& data) : - _data(data) - {} - - - string JsonFormatter::List::output(u_int indent_level) const + string + JsonFormatter::List::str(u_int indent_level) const { return "[\n" + - boost::algorithm::join(_data, ",\n") + "\n" + + boost::algorithm::join(data, ",\n") + "\n" + indent(indent_level) + "]"; } } + } diff --git a/client/utils/JsonFormatter.h b/client/utils/JsonFormatter.h index 79f7672d..48ed9d1d 100644 --- a/client/utils/JsonFormatter.h +++ b/client/utils/JsonFormatter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] SUSE LLC + * Copyright (c) [2019-2020] SUSE LLC * * All Rights Reserved. * @@ -26,15 +26,20 @@ #include #include + namespace snapper { + + using namespace std; + + namespace cli { /* Very simplistic JSON formatter, but enough for current requirements. * * If needed, this could be replaced by some modern library, for example: - * https://github.com/nlohmann/json + * libjson-c */ class JsonFormatter { @@ -43,11 +48,14 @@ namespace snapper class List; - using Data = std::vector>; + using Data = vector>; - JsonFormatter(const Data& data); + JsonFormatter(const Data& data) + : data(data), _inline(false) + { + } - void skip_format_values(const std::vector& skip_format_values) + void skip_format_values(const vector& skip_format_values) { _skip_format_values = skip_format_values; } @@ -57,19 +65,25 @@ namespace snapper _inline = is_inline; } - std::string output(u_int indent_level = 0) const; + string str(u_int indent_level = 0) const; private: - std::string json_attributes(u_int indent_level) const; + string json_attributes(u_int indent_level) const; - bool skip_format_value(const std::string& key) const; + bool skip_format_value(const string& key) const; - const Data& _data; + const Data& data; - std::vector _skip_format_values; + vector _skip_format_values; bool _inline; + + static string indent(u_int indent_level); + static string escape(const string& value); + static string quote(const string& value); + static string to_json(const string& value); + }; @@ -78,17 +92,21 @@ namespace snapper public: - List(const std::vector& data); + List(const vector& data) + : data(data) + { + } - std::string output(u_int indent_level = 0) const; + string str(u_int indent_level = 0) const; private: - const std::vector& _data; + const vector& data; }; } + } #endif diff --git a/client/utils/Table.cc b/client/utils/Table.cc index 371f8e24..7990ae22 100644 --- a/client/utils/Table.cc +++ b/client/utils/Table.cc @@ -11,7 +11,6 @@ using namespace std; -TableLineStyle Table::defaultStyle = Ascii; static const char * lines[][3] = { @@ -130,7 +129,7 @@ Table::Table() , _max_col (0) , _max_width(1, 0) , _width(0) - , _style (defaultStyle) + , _style (Ascii) , _screen_width(get_screen_width()) , _margin(0) , _force_break_after(-1) @@ -248,11 +247,15 @@ void Table::wrap(int force_break_after) _do_wrap = true; } -void Table::lineStyle (TableLineStyle st) { - if (st < _End) - _style = st; + +void +Table::set_style(TableStyle st) +{ + if (st < _End) + _style = st; } + void Table::margin(unsigned margin) { if (margin < (unsigned) (_screen_width/2)) _margin = margin; @@ -269,7 +272,3 @@ void Table::sort (unsigned by_column) { TableRow::Less comp (by_column); _rows.sort (comp); } - -// Local Variables: -// c-basic-offset: 2 -// End: diff --git a/client/utils/Table.h b/client/utils/Table.h index dd266c89..b5e1f12b 100644 --- a/client/utils/Table.h +++ b/client/utils/Table.h @@ -20,8 +20,8 @@ using std::ostream; using std::list; using std::vector; -//! table drawing style -enum TableLineStyle { +//! table style +enum TableStyle { Ascii = 0, ///< | - + Light, Heavy, @@ -101,8 +101,6 @@ class Table { public: typedef list container; - static TableLineStyle defaultStyle; - static const unsigned int numStyles = _End; void add (const TableRow& tr); @@ -111,7 +109,7 @@ public: bool empty () const { return _rows.empty(); } void sort (unsigned by_column); // columns start with 0... - void lineStyle (TableLineStyle st); + void set_style(TableStyle st); void wrap(int force_break_after = -1); void allowAbbrev(unsigned column); void margin(unsigned margin); @@ -132,8 +130,8 @@ private: mutable vector _max_width; //! table width (columns) int _width; - //! table line drawing style - TableLineStyle _style; + //! table style + TableStyle _style; //! amount of space we have to print this table int _screen_width; //! whether to abbreviate the respective column if needed diff --git a/client/utils/TableFormatter.cc b/client/utils/TableFormatter.cc index 330da3b2..40742b8e 100644 --- a/client/utils/TableFormatter.cc +++ b/client/utils/TableFormatter.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] SUSE LLC + * Copyright (c) [2019-2020] SUSE LLC * * All Rights Reserved. * @@ -23,69 +23,47 @@ #include "client/utils/TableFormatter.h" -using namespace std; namespace snapper { - namespace cli - { - - namespace - { - const TableLineStyle DEFAULT_STYLE = Table::defaultStyle; - } - - TableLineStyle TableFormatter::default_style() - { - return DEFAULT_STYLE; - } + using namespace std; - TableFormatter::TableFormatter( - vector> columns, - vector> rows) : - _columns(columns), _rows(rows), _style(default_style()) - {} - + namespace cli + { - TableFormatter::TableFormatter( - vector> columns, - vector> rows, - TableLineStyle style) : - _columns(columns), _rows(rows), _style(style) - {} + const TableStyle TableFormatter::default_style = Ascii; - string TableFormatter::output() const + string + TableFormatter::str() const { - Table::defaultStyle = _style; - Table table; + table.set_style(style); - TableHeader header; + TableHeader table_header; - for (auto column : _columns) - header.add(column.first, column.second); + for (const pair& column : header) + table_header.add(column.first, column.second); - table.setHeader(header); + table.setHeader(table_header); - for (auto row : _rows) + for (const vector& row : rows) { TableRow table_row; - for (auto value : row) + for (const string& value : row) table_row.add(value); table.add(table_row); } ostringstream stream; - stream << table; - return stream.str(); } } -} \ No newline at end of file + +} diff --git a/client/utils/TableFormatter.h b/client/utils/TableFormatter.h index ed1a3db0..cbbcdaea 100644 --- a/client/utils/TableFormatter.h +++ b/client/utils/TableFormatter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] SUSE LLC + * Copyright (c) [2019-2020] SUSE LLC * * All Rights Reserved. * @@ -28,8 +28,13 @@ #include "client/utils/Table.h" + namespace snapper { + + using namespace std; + + namespace cli { @@ -38,30 +43,26 @@ namespace snapper public: - static TableLineStyle default_style(); + static const TableStyle default_style; - TableFormatter( - std::vector> columns, - std::vector> rows); + TableFormatter(const vector>& header, + const vector>& rows, TableStyle style) + : header(header), rows(rows), style(style) + { + } - TableFormatter( - std::vector> columns, - std::vector> rows, - TableLineStyle style); - - std::string output() const; + string str() const; private: - std::vector> _columns; - - std::vector> _rows; - - TableLineStyle _style; + const vector> header; + const vector> rows; + const TableStyle style; }; } + } #endif diff --git a/testsuite/csv-formatter.cc b/testsuite/csv-formatter.cc index 8851bed1..84150516 100644 --- a/testsuite/csv-formatter.cc +++ b/testsuite/csv-formatter.cc @@ -29,5 +29,5 @@ BOOST_AUTO_TEST_CASE(test1) "\"value;1\";\"value\n2\";\"value\"\"3\"\n" "value1;\"\"\"value2\"\"\";value3\n"; - BOOST_CHECK_EQUAL(formatter.output(), result); + BOOST_CHECK_EQUAL(formatter.str(), result); } diff --git a/testsuite/json-formatter.cc b/testsuite/json-formatter.cc index 541a85ad..55fb7266 100644 --- a/testsuite/json-formatter.cc +++ b/testsuite/json-formatter.cc @@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE(test1_escape_values) snapper::cli::JsonFormatter formatter(data); - BOOST_CHECK_EQUAL(formatter.output(), expected_result); + BOOST_CHECK_EQUAL(formatter.str(), expected_result); } @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(test2_skip_format) formatter.skip_format_values({ "key1" }); - BOOST_CHECK_EQUAL(formatter.output(), expected_result); + BOOST_CHECK_EQUAL(formatter.str(), expected_result); } @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(test3_indent) snapper::cli::JsonFormatter formatter(data); - BOOST_CHECK_EQUAL(formatter.output(1), expected_result); + BOOST_CHECK_EQUAL(formatter.str(1), expected_result); } @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE(test4_inline) formatter.set_inline(true); - BOOST_CHECK_EQUAL(formatter.output(1), expected_result); + BOOST_CHECK_EQUAL(formatter.str(1), expected_result); } @@ -122,5 +122,5 @@ BOOST_AUTO_TEST_CASE(test5_list) "value3\n" "]"; - BOOST_CHECK_EQUAL(formatter.output(), result); + BOOST_CHECK_EQUAL(formatter.str(), result); }