From f7bfcdd7aae4faa8a13e203e0694e5428ffa6776 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 14 Oct 2020 18:00:04 +0900 Subject: [PATCH 01/25] fix: check all the elements in an array while checking if the array is array-of-tables or not (heterogeneous arrays are allowed, so there might be an array that has a table and an integer at the same time) --- toml/serializer.hpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index ed07f46..cf47710 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -244,7 +244,17 @@ struct serializer std::string operator()(const array_type& v) const { - if(!v.empty() && v.front().is_table())// v is an array of tables + if(v.empty()) + { + return std::string("[]"); + } + + // Since TOML v0.5.0, heterogeneous arrays are allowed. So we need to + // check all the element in an array to check if the array is an array + // of tables. + const bool is_array_of_tables = std::all_of(v.begin(), v.end(), + [](const value_type& elem) {return elem.is_table();}); + if(is_array_of_tables) { // if it's not inlined, we need to add `[[table.key]]`. // but if it can be inlined, @@ -322,10 +332,6 @@ struct serializer } return token; } - if(v.empty()) - { - return std::string("[]"); - } // not an array of tables. normal array. // first, try to make it inline if none of the elements have a comment. From 382e3dc3ab3ea26ba8567f3ecd84b476afcec44a Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 14 Oct 2020 22:27:29 +0900 Subject: [PATCH 02/25] refactor: use serializer::is_array_of_tables --- toml/serializer.hpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index cf47710..433997b 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -248,13 +248,7 @@ struct serializer { return std::string("[]"); } - - // Since TOML v0.5.0, heterogeneous arrays are allowed. So we need to - // check all the element in an array to check if the array is an array - // of tables. - const bool is_array_of_tables = std::all_of(v.begin(), v.end(), - [](const value_type& elem) {return elem.is_table();}); - if(is_array_of_tables) + if(this->is_array_of_tables(v)) { // if it's not inlined, we need to add `[[table.key]]`. // but if it can be inlined, @@ -674,8 +668,16 @@ struct serializer bool is_array_of_tables(const value_type& v) const { if(!v.is_array()) {return false;} - const auto& a = v.as_array(); - return !a.empty() && a.front().is_table(); + return is_array_of_tables(v.as_array()); + } + bool is_array_of_tables(const array_type& v) const + { + // Since TOML v0.5.0, heterogeneous arrays are allowed. So we need to + // check all the element in an array to check if the array is an array + // of tables. + return std::all_of(v.begin(), v.end(), [](const value_type& elem) { + return elem.is_table(); + }); } private: From 9090b8273ce536bbf26ccff1fa3b492968cca767 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 18 Oct 2020 17:20:06 +0900 Subject: [PATCH 03/25] refactor: move array-of-table stuff to a function --- toml/serializer.hpp | 159 +++++++++++++++++++++++--------------------- 1 file changed, 82 insertions(+), 77 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 433997b..385e79b 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -250,86 +250,12 @@ struct serializer } if(this->is_array_of_tables(v)) { - // if it's not inlined, we need to add `[[table.key]]`. - // but if it can be inlined, - // ``` - // table.key = [ - // {...}, - // # comment - // {...}, - // ] - // ``` - if(this->can_be_inlined_) - { - std::string token; - if(!keys_.empty()) - { - token += format_key(keys_.back()); - token += " = "; - } - bool failed = false; - token += "[\n"; - for(const auto& item : v) - { - // if an element of the table has a comment, the table - // cannot be inlined. - if(this->has_comment_inside(item.as_table())) - { - failed = true; - break; - } - if(!no_comment_) - { - for(const auto& c : item.comments()) - { - token += '#'; - token += c; - token += '\n'; - } - } - - const auto t = this->make_inline_table(item.as_table()); - - if(t.size() + 1 > width_ || // +1 for the last comma {...}, - std::find(t.cbegin(), t.cend(), '\n') != t.cend()) - { - failed = true; - break; - } - token += t; - token += ",\n"; - } - if(!failed) - { - token += "]\n"; - return token; - } - // if failed, serialize them as [[array.of.tables]]. - } - - std::string token; - for(const auto& item : v) - { - if(!no_comment_) - { - for(const auto& c : item.comments()) - { - token += '#'; - token += c; - token += '\n'; - } - } - token += "[["; - token += format_keys(keys_); - token += "]]\n"; - token += this->make_multiline_table(item.as_table()); - } - return token; + return make_array_of_tables(v); } // not an array of tables. normal array. // first, try to make it inline if none of the elements have a comment. - if(!this->has_comment_inside(v)) + if( ! this->has_comment_inside(v)) { const auto inl = this->make_inline_array(v); if(inl.size() < this->width_ && @@ -350,7 +276,7 @@ struct serializer token += "[\n"; for(const auto& item : v) { - if(!item.comments().empty() && !no_comment_) + if( ! item.comments().empty() && !no_comment_) { // if comment exists, the element must be the only element in the line. // e.g. the following is not allowed. @@ -665,6 +591,85 @@ struct serializer return token; } + std::string make_array_of_tables(const array_type& v) const + { + // if it's not inlined, we need to add `[[table.key]]`. + // but if it can be inlined, + // ``` + // table.key = [ + // {...}, + // # comment + // {...}, + // ] + // ``` + if(this->can_be_inlined_) + { + std::string token; + if(!keys_.empty()) + { + token += format_key(keys_.back()); + token += " = "; + } + bool failed = false; + token += "[\n"; + for(const auto& item : v) + { + // if an element of the table has a comment, the table + // cannot be inlined. + if(this->has_comment_inside(item.as_table())) + { + failed = true; + break; + } + if(!no_comment_) + { + for(const auto& c : item.comments()) + { + token += '#'; + token += c; + token += '\n'; + } + } + + const auto t = this->make_inline_table(item.as_table()); + + if(t.size() + 1 > width_ || // +1 for the last comma {...}, + std::find(t.cbegin(), t.cend(), '\n') != t.cend()) + { + failed = true; + break; + } + token += t; + token += ",\n"; + } + if(!failed) + { + token += "]\n"; + return token; + } + // if failed, serialize them as [[array.of.tables]]. + } + + std::string token; + for(const auto& item : v) + { + if(!no_comment_) + { + for(const auto& c : item.comments()) + { + token += '#'; + token += c; + token += '\n'; + } + } + token += "[["; + token += format_keys(keys_); + token += "]]\n"; + token += this->make_multiline_table(item.as_table()); + } + return token; + } + bool is_array_of_tables(const value_type& v) const { if(!v.is_array()) {return false;} From fd50b11523e247efa21d90eafe70eccaec7121b9 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 18 Oct 2020 18:30:04 +0900 Subject: [PATCH 04/25] refactor: add write_comments() --- toml/serializer.hpp | 56 ++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 385e79b..79a6b92 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -523,15 +523,8 @@ struct serializer continue; } - if(!kv.second.comments().empty() && !no_comment_) - { - for(const auto& c : kv.second.comments()) - { - token += '#'; - token += c; - token += '\n'; - } - } + token += write_comments(kv.second); + const auto key_and_sep = format_key(kv.first) + " = "; const auto residual_width = (this->width_ > key_and_sep.size()) ? this->width_ - key_and_sep.size() : 0; @@ -577,15 +570,7 @@ struct serializer tmp += '\n'; } - if(!kv.second.comments().empty() && !no_comment_) - { - for(const auto& c : kv.second.comments()) - { - token += '#'; - token += c; - token += '\n'; - } - } + token += write_comments(kv.second); token += tmp; } return token; @@ -621,15 +606,8 @@ struct serializer failed = true; break; } - if(!no_comment_) - { - for(const auto& c : item.comments()) - { - token += '#'; - token += c; - token += '\n'; - } - } + // write comments for the table itself + token += write_comments(item); const auto t = this->make_inline_table(item.as_table()); @@ -653,15 +631,7 @@ struct serializer std::string token; for(const auto& item : v) { - if(!no_comment_) - { - for(const auto& c : item.comments()) - { - token += '#'; - token += c; - token += '\n'; - } - } + token += write_comments(item); token += "[["; token += format_keys(keys_); token += "]]\n"; @@ -670,6 +640,20 @@ struct serializer return token; } + std::string write_comments(const value_type& v) const + { + std::string retval; + if(this->no_comment_) {return retval;} + + for(const auto& c : v.comments()) + { + retval += '#'; + retval += c; + retval += '\n'; + } + return retval; + } + bool is_array_of_tables(const value_type& v) const { if(!v.is_array()) {return false;} From fce6ff317e2dabe330625e2eda7d4819278e3ea6 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 18 Oct 2020 18:36:05 +0900 Subject: [PATCH 05/25] refactor: distinguish the reason of failure --- toml/serializer.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 79a6b92..95ea1ff 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -595,7 +595,9 @@ struct serializer token += format_key(keys_.back()); token += " = "; } - bool failed = false; + + bool exceed_column = false; + bool has_comment = false; token += "[\n"; for(const auto& item : v) { @@ -603,7 +605,7 @@ struct serializer // cannot be inlined. if(this->has_comment_inside(item.as_table())) { - failed = true; + has_comment = true; break; } // write comments for the table itself @@ -614,13 +616,13 @@ struct serializer if(t.size() + 1 > width_ || // +1 for the last comma {...}, std::find(t.cbegin(), t.cend(), '\n') != t.cend()) { - failed = true; + exceed_column = true; break; } token += t; token += ",\n"; } - if(!failed) + if(!exceed_column && !has_comment) { token += "]\n"; return token; From 908b91079b6cf603f2d08094d84b37b660f0de07 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 18 Oct 2020 20:43:33 +0900 Subject: [PATCH 06/25] fix: distinguish the comments and try to keep it If a value has a comment, we need to try to write it explicitly. --- toml/serializer.hpp | 85 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 95ea1ff..e702ead 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -97,8 +97,10 @@ struct serializer const int float_prec = std::numeric_limits::max_digits10, const bool can_be_inlined = false, const bool no_comment = false, - std::vector ks = {}) + std::vector ks = {}, + const bool value_has_comment = false) : can_be_inlined_(can_be_inlined), no_comment_(no_comment), + value_has_comment_(value_has_comment && !no_comment), float_prec_(float_prec), width_(w), keys_(std::move(ks)) {} ~serializer() = default; @@ -483,8 +485,10 @@ struct serializer for(const auto& item : v) { if(is_first) {is_first = false;} else {token += ',';} - token += visit(serializer((std::numeric_limits::max)(), - this->float_prec_, true), item); + token += visit(serializer( + (std::numeric_limits::max)(), this->float_prec_, + /* inlined */ true, /*no comment*/ false, /*keys*/ {}, + /*has_comment*/ !item.comments().empty()), item); } token += ']'; return token; @@ -503,8 +507,10 @@ struct serializer if(is_first) {is_first = false;} else {token += ',';} token += format_key(kv.first); token += '='; - token += visit(serializer((std::numeric_limits::max)(), - this->float_prec_, true), kv.second); + token += visit(serializer( + (std::numeric_limits::max)(), this->float_prec_, + /* inlined */ true, /*no comment*/ false, /*keys*/ {}, + /*has_comment*/ !kv.second.comments().empty()), kv.second); } token += '}'; return token; @@ -514,8 +520,16 @@ struct serializer { std::string token; - // print non-table stuff first. because after printing [foo.bar], the - // remaining non-table values will be assigned into [foo.bar], not [foo] + // print non-table elements first. + // ```toml + // [foo] # a table we're writing now here + // key = "value" # <- non-table element, "key" + // # ... + // [foo.bar] # <- table element, "bar" + // ``` + // because after printing [foo.bar], the remaining non-table values will + // be assigned into [foo.bar], not [foo]. Those values should be printed + // earlier. for(const auto& kv : v) { if(kv.second.is_table() || is_array_of_tables(kv.second)) @@ -529,8 +543,10 @@ struct serializer const auto residual_width = (this->width_ > key_and_sep.size()) ? this->width_ - key_and_sep.size() : 0; token += key_and_sep; - token += visit(serializer(residual_width, this->float_prec_, true), - kv.second); + token += visit(serializer(residual_width, this->float_prec_, + /*can be inlined*/ true, /*no comment*/ false, /*keys*/ {}, + /*has_comment*/ !kv.second.comments().empty()), kv.second); + if(token.back() != '\n') { token += '\n'; @@ -556,8 +572,8 @@ struct serializer ks.push_back(kv.first); auto tmp = visit(serializer(this->width_, this->float_prec_, - !multiline_table_printed, this->no_comment_, ks), - kv.second); + !multiline_table_printed, this->no_comment_, ks, + /*has_comment*/ !kv.second.comments().empty()), kv.second); if((!multiline_table_printed) && std::find(tmp.cbegin(), tmp.cend(), '\n') != tmp.cend()) @@ -579,7 +595,7 @@ struct serializer std::string make_array_of_tables(const array_type& v) const { // if it's not inlined, we need to add `[[table.key]]`. - // but if it can be inlined, + // but if it can be inlined, we can format it as the following. // ``` // table.key = [ // {...}, @@ -587,7 +603,33 @@ struct serializer // {...}, // ] // ``` - if(this->can_be_inlined_) + // This function checks if inlinization is possible or not, and then + // format the array-of-tables in a proper way. + // + // Note about comments: + // + // If the array itself has a comment (value_has_comment_ == true), we + // should try to make it inline. + // ```toml + // # comment about array + // array = [ + // # comment about table element + // {of = "table"} + // ] + // ``` + // If it is formatted as a multiline table, the two comments becomes + // indistinguishable. + // ```toml + // # comment about array + // # comment about table element + // [[array]] + // of = "table" + // ``` + // So we need to try to make it inline, and it force-inlines regardless + // of the line width limit. + // It may fail if the element of a table has comment. In that case, + // the array-of-tables will be formatted as a multiline table. + if(this->can_be_inlined_ || this->value_has_comment_) { std::string token; if(!keys_.empty()) @@ -596,8 +638,7 @@ struct serializer token += " = "; } - bool exceed_column = false; - bool has_comment = false; + bool failed = false; token += "[\n"; for(const auto& item : v) { @@ -605,7 +646,7 @@ struct serializer // cannot be inlined. if(this->has_comment_inside(item.as_table())) { - has_comment = true; + failed = true; break; } // write comments for the table itself @@ -616,13 +657,18 @@ struct serializer if(t.size() + 1 > width_ || // +1 for the last comma {...}, std::find(t.cbegin(), t.cend(), '\n') != t.cend()) { - exceed_column = true; - break; + // if the value itself has a comment, ignore the line width limit + if( ! this->value_has_comment_) + { + failed = true; + break; + } } token += t; token += ",\n"; } - if(!exceed_column && !has_comment) + + if( ! failed) { token += "]\n"; return token; @@ -675,6 +721,7 @@ struct serializer bool can_be_inlined_; bool no_comment_; + bool value_has_comment_; int float_prec_; std::size_t width_; std::vector keys_; From 0dafa7ee42739311ba6d455a41700febdeb11263 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 18 Oct 2020 20:45:12 +0900 Subject: [PATCH 07/25] test: add case where a table should be inlined array-of-table implicitly defines an array. If the array itself has a comment, we need to format it explicitly. --- tests/test_serialize_file.cpp | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/test_serialize_file.cpp b/tests/test_serialize_file.cpp index f7384bb..b5c408e 100644 --- a/tests/test_serialize_file.cpp +++ b/tests/test_serialize_file.cpp @@ -10,6 +10,7 @@ #include #include #include +#include template class Table, @@ -303,3 +304,60 @@ BOOST_AUTO_TEST_CASE(test_format_key) BOOST_TEST("\"special-chars-\\\\-\\\"-\\b-\\f-\\r-\\n-\\t\"" == toml::format_key(key)); } } + +// In toml11, an implicitly-defined value does not have any comments. +// So, in the following file, +// ```toml +// # comment +// [[array-of-tables]] +// foo = "bar" +// ``` +// The array named "array-of-tables" does not have the comment, but the first +// element of the array has. That means that, the above file is equivalent to +// the following. +// ```toml +// array-of-tables = [ +// # comment +// {foo = "bar"}, +// ] +// ``` +// If the array itself has a comment (value_has_comment_ == true), we should try +// to make it inline. +// ```toml +// # comment about array +// array-of-tables = [ +// # comment about table element +// {foo = "bar"} +// ] +// ``` +// If it is formatted as a multiline table, the two comments becomes +// indistinguishable. +// ```toml +// # comment about array +// # comment about table element +// [[array-of-tables]] +// foo = "bar" +// ``` +// So we need to try to make it inline, and it force-inlines regardless +// of the line width limit. +// It may fail if the element of a table has comment. In that case, +// the array-of-tables will be formatted as a multiline table. +BOOST_AUTO_TEST_CASE(test_distinguish_comment) +{ + const std::string str = R"(# comment about array itself +array_of_table = [ + # comment about the first element (table) + {key = "value"}, +])"; + std::istringstream iss(str); + const auto data = toml::parse(iss); + const auto serialized = toml::format(data, /*width = */ 0); + + std::istringstream reparse(serialized); + const auto parsed = toml::parse(reparse); + + BOOST_TEST(parsed.at("array_of_table").comments().size() == 1u); + BOOST_TEST(parsed.at("array_of_table").comments().front() == " comment about array itself"); + BOOST_TEST(parsed.at("array_of_table").at(0).comments().size() == 1u); + BOOST_TEST(parsed.at("array_of_table").at(0).comments().front() == " comment about the first element (table)"); +} From a6581ee66b44bd70b2f8c51fa10895e499385d54 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 3 Nov 2020 20:34:01 +0900 Subject: [PATCH 08/25] fix: an empty array is not an array of table --- toml/serializer.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index e702ead..fec7d08 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -704,7 +704,7 @@ struct serializer bool is_array_of_tables(const value_type& v) const { - if(!v.is_array()) {return false;} + if(!v.is_array() || v.as_array().empty()) {return false;} return is_array_of_tables(v.as_array()); } bool is_array_of_tables(const array_type& v) const From 1ead14589e1ba07ca6bf82743c936091840165f1 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 4 Nov 2020 23:24:02 +0900 Subject: [PATCH 09/25] fix: check if it is empty before calling back() --- toml/region.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toml/region.hpp b/toml/region.hpp index 6761aed..37ba3a3 100644 --- a/toml/region.hpp +++ b/toml/region.hpp @@ -344,7 +344,7 @@ struct region final : public region_base { // unwrap the first '#' by std::next. auto str = make_string(std::next(comment_found), iter); - if(str.back() == '\r') {str.pop_back();} + if(!str.empty() && str.back() == '\r') {str.pop_back();} com.push_back(std::move(str)); } else @@ -397,7 +397,7 @@ struct region final : public region_base { // unwrap the first '#' by std::next. auto str = make_string(std::next(comment_found), this->line_end()); - if(str.back() == '\r') {str.pop_back();} + if(!str.empty() && str.back() == '\r') {str.pop_back();} com.push_back(std::move(str)); } } From 9b472a6c72fc9668446ee8c258594a787ed60f28 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 4 Nov 2020 23:24:59 +0900 Subject: [PATCH 10/25] fix: check it is empty before calling back --- toml/serializer.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index fec7d08..bef1827 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -122,7 +122,7 @@ struct serializer std::snprintf(buf.data(), buf.size(), fmt, this->float_prec_, f); std::string token(buf.begin(), std::prev(buf.end())); - if(token.back() == '.') // 1. => 1.0 + if(!token.empty() && token.back() == '.') // 1. => 1.0 { token += '0'; } @@ -304,7 +304,7 @@ struct serializer token += '\n'; } token += toml::visit(*this, item); - if(token.back() == '\n') {token.pop_back();} + if(!token.empty() && token.back() == '\n') {token.pop_back();} token += ",\n"; continue; } @@ -312,7 +312,7 @@ struct serializer next_elem += toml::visit(*this, item); // comma before newline. - if(next_elem.back() == '\n') {next_elem.pop_back();} + if(!next_elem.empty() && next_elem.back() == '\n') {next_elem.pop_back();} // if current line does not exceeds the width limit, continue. if(current_line.size() + next_elem.size() + 1 < this->width_) @@ -339,7 +339,10 @@ struct serializer } if(!current_line.empty()) { - if(current_line.back() != '\n') {current_line += '\n';} + if(!current_line.empty() && current_line.back() != '\n') + { + current_line += '\n'; + } token += current_line; } token += "]\n"; From 935da51769ad40732879780214c1ac674b37f621 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Wed, 9 Dec 2020 10:15:38 +0000 Subject: [PATCH 11/25] Add missing include for ostringstream Since region.hpp no longer includes (but only ), source_location.hpp no longer includes a header that provides std::ostringstream. Including fixes this. --- toml/source_location.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/toml/source_location.hpp b/toml/source_location.hpp index a386710..fa175b5 100644 --- a/toml/source_location.hpp +++ b/toml/source_location.hpp @@ -3,6 +3,7 @@ #ifndef TOML11_SOURCE_LOCATION_HPP #define TOML11_SOURCE_LOCATION_HPP #include +#include #include "region.hpp" From db2d33ca4be2315549a6b46c17617629180b1723 Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Wed, 9 Dec 2020 10:39:10 +0000 Subject: [PATCH 12/25] Add missing header for std::out_of_range exception Failure seen on GCC 4.8.5 when including "toml/value.hpp". --- toml/comments.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/toml/comments.hpp b/toml/comments.hpp index 1e17544..92fc8e1 100644 --- a/toml/comments.hpp +++ b/toml/comments.hpp @@ -4,6 +4,7 @@ #define TOML11_COMMENTS_HPP #include #include +#include #include #include #include From 2fb8793f1af4a4c1727eca7780597ce5cafa6629 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 29 Dec 2020 18:52:07 +0900 Subject: [PATCH 13/25] doc: add document about basic_value and toml::into related to #146. --- README.md | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4bd139c..fcc4b0e 100644 --- a/README.md +++ b/README.md @@ -1303,9 +1303,9 @@ struct foo double b; std::string c; - toml::table into_toml() const // you need to mark it const. + toml::value into_toml() const // you need to mark it const. { - return toml::table{{"a", this->a}, {"b", this->b}, {"c", this->c}}; + return toml::value{{"a", this->a}, {"b", this->b}, {"c", this->c}}; } }; } // ext @@ -1332,9 +1332,9 @@ namespace toml template<> struct into { - static toml::table into_toml(const ext::foo& f) + static toml::value into_toml(const ext::foo& f) { - return toml::table{{"a", f.a}, {"b", f.b}, {"c", f.c}}; + return toml::value{{"a", f.a}, {"b", f.b}, {"c", f.c}}; } }; } // toml @@ -1346,6 +1346,27 @@ toml::value v(f); Any type that can be converted to `toml::value`, e.g. `int`, `toml::table` and `toml::array` are okay to return from `into_toml`. +You can also return a custom `toml::basic_value` from `toml::into`. + +```cpp +namespace toml +{ +template<> +struct into +{ + static toml::basic_value into_toml(const ext::foo& f) + { + toml::basic_value v{{"a", f.a}, {"b", f.b}, {"c", f.c}}; + v.comments().push_back(" comment"); + return v; + } +}; +} // toml +``` + +But note that, if this `basic_value` would be assigned into other `toml::value` +that discards `comments`, the comments would be dropped. + ## Formatting user-defined error messages When you encounter an error after you read the toml value, you may want to From e9144b41fbedaf63cefd38afe40b66c5c29f3bb5 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 29 Dec 2020 18:53:10 +0900 Subject: [PATCH 14/25] test: returning toml::value directly from into --- tests/test_extended_conversions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_extended_conversions.cpp b/tests/test_extended_conversions.cpp index 428f477..47cbc97 100644 --- a/tests/test_extended_conversions.cpp +++ b/tests/test_extended_conversions.cpp @@ -70,9 +70,9 @@ struct from template<> struct into { - static toml::table into_toml(const extlib::foo& f) + static toml::value into_toml(const extlib::foo& f) { - return toml::table{{"a", f.a}, {"b", f.b}}; + return toml::value{{"a", f.a}, {"b", f.b}}; } }; From d3de13656205d31c347d35d1aaba333fe893099d Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 25 Jan 2021 17:25:29 +0900 Subject: [PATCH 15/25] doc: simplity example code a bit --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fcc4b0e..f2ce9e3 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ toml11 is a C++11 (or later) header-only toml parser/encoder depending only on C int main() { + // ```toml + // title = "an example toml file" + // nums = [3, 1, 4, 1, 5] + // ``` auto data = toml::parse("example.toml"); // find a value with the specified type from a table @@ -37,9 +41,9 @@ int main() std::vector nums = toml::find>(data, "nums"); // access with STL-like manner - if(not data.at("a").contains("b")) + if(not data.contains("foo")) { - data["a"]["b"] = "c"; + data["foo"] = "bar"; } // pass a fallback From 08859c36d044ae321d36af1e36e2cc54c2503566 Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Sat, 30 Jan 2021 20:04:00 +0000 Subject: [PATCH 16/25] Fix typo in error message --- toml/parser.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml/parser.hpp b/toml/parser.hpp index 9dbfd7b..a1fa318 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -930,7 +930,7 @@ parse_key(location& loc) return ok(std::make_pair(std::vector(1, smpl.unwrap().first), smpl.unwrap().second)); } - return err(format_underline("toml::parse_key: an invalid key appeaed.", + return err(format_underline("toml::parse_key: an invalid key appeared.", {{source_location(loc), "is not a valid key"}}, { "bare keys : non-empty strings composed only of [A-Za-z0-9_-].", "quoted keys: same as \"basic strings\" or 'literal strings'.", From b924e70e3cda1f3044c3b9879e22ced85d62b3a5 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 25 Mar 2021 11:44:11 +0900 Subject: [PATCH 17/25] feat: add a simple way to disable As jwillikers pointed out in #150, there is a case where compiler defines the corresponding feature test macro of but is actually not available. The macro is a way to disable the feature regardless of the status of feature test macro. --- toml/parser.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/toml/parser.hpp b/toml/parser.hpp index a1fa318..c3df644 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -13,12 +13,14 @@ #include "types.hpp" #include "value.hpp" +#ifndef TOML11_DISABLE_STD_FILESYSTEM #ifdef __cpp_lib_filesystem #if __has_include() #define TOML11_HAS_STD_FILESYSTEM #include #endif // has_include() #endif // __cpp_lib_filesystem +#endif // TOML11_DISABLE_STD_FILESYSTEM namespace toml { From 970f7cb36a2471c9a8bef5953d486b345e10531f Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 25 Mar 2021 13:34:30 +0900 Subject: [PATCH 18/25] ci: trying to update boost installation settings [skip travis] [skip appveyor] --- .github/workflows/main.yml | 173 +++++++++++++++++++------------------ 1 file changed, 90 insertions(+), 83 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dfcf41f..07aa1ed 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,88 +3,88 @@ name: build on: [push, pull_request] jobs: - build-linux-gcc: - runs-on: Ubuntu-18.04 - strategy: - matrix: - # g++-4.8 and 4.9 are tested on Travis.CI. - compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] - standard: ['11', '14', '17', '20'] - exclude: - - {compiler: 'g++-5', standard: '17'} - - {compiler: 'g++-6', standard: '17'} - - {compiler: 'g++-5', standard: '20'} - - {compiler: 'g++-6', standard: '20'} - - {compiler: 'g++-7', standard: '20'} - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: true - - name: Install - run: | - sudo apt-add-repository ppa:mhier/libboost-latest - sudo apt-get update - sudo apt-get install boost1.70 - if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then - sudo apt-add-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install ${{ matrix.compiler }} - fi - - name: Configure - run: | - mkdir build && cd build - if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then - cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON - else - cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} - fi - - name: Build - run: | - cd build && cmake --build . - - name: Test - run: | - cd build && ctest --output-on-failure - build-linux-clang: - runs-on: Ubuntu-18.04 - strategy: - matrix: - compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] - standard: ['11', '14', '17', '20'] - exclude: - - {compiler: '3.9', standard: '17'} - - {compiler: '4.0', standard: '17'} - - {compiler: '5.0', standard: '17'} - - {compiler: '3.9', standard: '20'} - - {compiler: '4.0', standard: '20'} - - {compiler: '5.0', standard: '20'} - - {compiler: '6.0', standard: '20'} - - {compiler: '7', standard: '20'} - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: true - - name: Install - run: | - sudo apt-add-repository ppa:mhier/libboost-latest - sudo apt-get update - sudo apt-get install boost1.70 - if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then - sudo apt-add-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install clang-${{ matrix.compiler }} - fi - - name: Configure - run: | - mkdir build && cd build - cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} - - name: Build - run: | - cd build && cmake --build . - - name: Test - run: | - cd build && ctest --output-on-failure +# build-linux-gcc: +# runs-on: Ubuntu-18.04 +# strategy: +# matrix: +# # g++-4.8 and 4.9 are tested on Travis.CI. +# compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] +# standard: ['11', '14', '17', '20'] +# exclude: +# - {compiler: 'g++-5', standard: '17'} +# - {compiler: 'g++-6', standard: '17'} +# - {compiler: 'g++-5', standard: '20'} +# - {compiler: 'g++-6', standard: '20'} +# - {compiler: 'g++-7', standard: '20'} +# steps: +# - name: Checkout +# uses: actions/checkout@v2 +# with: +# submodules: true +# - name: Install +# run: | +# sudo apt-add-repository ppa:mhier/libboost-latest +# sudo apt-get update +# sudo apt-get install boost1.70 +# if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then +# sudo apt-add-repository ppa:ubuntu-toolchain-r/test +# sudo apt-get update +# sudo apt-get install ${{ matrix.compiler }} +# fi +# - name: Configure +# run: | +# mkdir build && cd build +# if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then +# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON +# else +# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} +# fi +# - name: Build +# run: | +# cd build && cmake --build . +# - name: Test +# run: | +# cd build && ctest --output-on-failure +# build-linux-clang: +# runs-on: Ubuntu-18.04 +# strategy: +# matrix: +# compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] +# standard: ['11', '14', '17', '20'] +# exclude: +# - {compiler: '3.9', standard: '17'} +# - {compiler: '4.0', standard: '17'} +# - {compiler: '5.0', standard: '17'} +# - {compiler: '3.9', standard: '20'} +# - {compiler: '4.0', standard: '20'} +# - {compiler: '5.0', standard: '20'} +# - {compiler: '6.0', standard: '20'} +# - {compiler: '7', standard: '20'} +# steps: +# - name: Checkout +# uses: actions/checkout@v2 +# with: +# submodules: true +# - name: Install +# run: | +# sudo apt-add-repository ppa:mhier/libboost-latest +# sudo apt-get update +# sudo apt-get install boost1.70 +# if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then +# sudo apt-add-repository ppa:ubuntu-toolchain-r/test +# sudo apt-get update +# sudo apt-get install clang-${{ matrix.compiler }} +# fi +# - name: Configure +# run: | +# mkdir build && cd build +# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} +# - name: Build +# run: | +# cd build && cmake --build . +# - name: Test +# run: | +# cd build && ctest --output-on-failure build-windows-msvc: runs-on: windows-2019 strategy: @@ -96,6 +96,13 @@ jobs: uses: actions/checkout@v2 with: submodules: true + - name: Install + run: | + (New-Object System.Net.WebClient).DownloadFile("https://github.com/actions/boost-versions/releases/download/1.72.0-20200608.4/boost-1.72.0-win32-msvc14.2-x86_64.tar.gz", "$env:TEMP\\boost.tar.gz") + 7z.exe x "$env:TEMP\\boost.tar.gz" -o"$env:TEMP\\boostArchive" -y | Out-Null + 7z.exe x "$env:TEMP\\boostArchive" -o"$env:TEMP\\boost" -y | Out-Null + Push-Location -Path "$env:TEMP\\boost" + Invoke-Expression .\\setup.ps1 - uses: ilammy/msvc-dev-cmd@v1 - name: Configure shell: cmd @@ -103,7 +110,7 @@ jobs: file --mime-encoding tests/test_literals.cpp mkdir build cd build - cmake ../ -G "NMake Makefiles" -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DBoost_ADDITIONAL_VERSIONS=1.72.0 -DBoost_USE_MULTITHREADED=ON -DBoost_ARCHITECTURE=-x64 -DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT=%BOOST_ROOT_1_72_0% + cmake ../ -G "NMake Makefiles" -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT="C:\\hostedtoolcache\\windows\\Boost\\1.72.0\\x86_64" - name: Build working-directory: ./build run: | From 2c5cc431fe8b732fda8d1e433c699a7636f64633 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 25 Mar 2021 14:33:55 +0900 Subject: [PATCH 19/25] ci: re-activate linux CI --- .github/workflows/main.yml | 164 ++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 07aa1ed..452569c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,88 +3,88 @@ name: build on: [push, pull_request] jobs: -# build-linux-gcc: -# runs-on: Ubuntu-18.04 -# strategy: -# matrix: -# # g++-4.8 and 4.9 are tested on Travis.CI. -# compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] -# standard: ['11', '14', '17', '20'] -# exclude: -# - {compiler: 'g++-5', standard: '17'} -# - {compiler: 'g++-6', standard: '17'} -# - {compiler: 'g++-5', standard: '20'} -# - {compiler: 'g++-6', standard: '20'} -# - {compiler: 'g++-7', standard: '20'} -# steps: -# - name: Checkout -# uses: actions/checkout@v2 -# with: -# submodules: true -# - name: Install -# run: | -# sudo apt-add-repository ppa:mhier/libboost-latest -# sudo apt-get update -# sudo apt-get install boost1.70 -# if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then -# sudo apt-add-repository ppa:ubuntu-toolchain-r/test -# sudo apt-get update -# sudo apt-get install ${{ matrix.compiler }} -# fi -# - name: Configure -# run: | -# mkdir build && cd build -# if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then -# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON -# else -# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -# fi -# - name: Build -# run: | -# cd build && cmake --build . -# - name: Test -# run: | -# cd build && ctest --output-on-failure -# build-linux-clang: -# runs-on: Ubuntu-18.04 -# strategy: -# matrix: -# compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] -# standard: ['11', '14', '17', '20'] -# exclude: -# - {compiler: '3.9', standard: '17'} -# - {compiler: '4.0', standard: '17'} -# - {compiler: '5.0', standard: '17'} -# - {compiler: '3.9', standard: '20'} -# - {compiler: '4.0', standard: '20'} -# - {compiler: '5.0', standard: '20'} -# - {compiler: '6.0', standard: '20'} -# - {compiler: '7', standard: '20'} -# steps: -# - name: Checkout -# uses: actions/checkout@v2 -# with: -# submodules: true -# - name: Install -# run: | -# sudo apt-add-repository ppa:mhier/libboost-latest -# sudo apt-get update -# sudo apt-get install boost1.70 -# if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then -# sudo apt-add-repository ppa:ubuntu-toolchain-r/test -# sudo apt-get update -# sudo apt-get install clang-${{ matrix.compiler }} -# fi -# - name: Configure -# run: | -# mkdir build && cd build -# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -# - name: Build -# run: | -# cd build && cmake --build . -# - name: Test -# run: | -# cd build && ctest --output-on-failure + build-linux-gcc: + runs-on: Ubuntu-18.04 + strategy: + matrix: + # g++-4.8 and 4.9 are tested on Travis.CI. + compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] + standard: ['11', '14', '17', '20'] + exclude: + - {compiler: 'g++-5', standard: '17'} + - {compiler: 'g++-6', standard: '17'} + - {compiler: 'g++-5', standard: '20'} + - {compiler: 'g++-6', standard: '20'} + - {compiler: 'g++-7', standard: '20'} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install + run: | + sudo apt-add-repository ppa:mhier/libboost-latest + sudo apt-get update + sudo apt-get install boost1.70 + if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then + sudo apt-add-repository ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get install ${{ matrix.compiler }} + fi + - name: Configure + run: | + mkdir build && cd build + if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then + cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON + else + cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} + fi + - name: Build + run: | + cd build && cmake --build . + - name: Test + run: | + cd build && ctest --output-on-failure + build-linux-clang: + runs-on: Ubuntu-18.04 + strategy: + matrix: + compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] + standard: ['11', '14', '17', '20'] + exclude: + - {compiler: '3.9', standard: '17'} + - {compiler: '4.0', standard: '17'} + - {compiler: '5.0', standard: '17'} + - {compiler: '3.9', standard: '20'} + - {compiler: '4.0', standard: '20'} + - {compiler: '5.0', standard: '20'} + - {compiler: '6.0', standard: '20'} + - {compiler: '7', standard: '20'} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install + run: | + sudo apt-add-repository ppa:mhier/libboost-latest + sudo apt-get update + sudo apt-get install boost1.70 + if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then + sudo apt-add-repository ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get install clang-${{ matrix.compiler }} + fi + - name: Configure + run: | + mkdir build && cd build + cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} + - name: Build + run: | + cd build && cmake --build . + - name: Test + run: | + cd build && ctest --output-on-failure build-windows-msvc: runs-on: windows-2019 strategy: From 5e0ee32854397cfe2a0531d7c7bff90ce953a8cb Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 25 Mar 2021 14:38:53 +0900 Subject: [PATCH 20/25] ci: trying to add macos to github actions [skip travis] [skip appveyor] it is already listed in travis CI, but not in the GH actions --- .github/workflows/main.yml | 229 ++++++++++++++++++++----------------- 1 file changed, 127 insertions(+), 102 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 452569c..4e36ed9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,19 +3,94 @@ name: build on: [push, pull_request] jobs: - build-linux-gcc: - runs-on: Ubuntu-18.04 +# build-linux-gcc: +# runs-on: Ubuntu-18.04 +# strategy: +# matrix: +# # g++-4.8 and 4.9 are tested on Travis.CI. +# compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] +# standard: ['11', '14', '17', '20'] +# exclude: +# - {compiler: 'g++-5', standard: '17'} +# - {compiler: 'g++-6', standard: '17'} +# - {compiler: 'g++-5', standard: '20'} +# - {compiler: 'g++-6', standard: '20'} +# - {compiler: 'g++-7', standard: '20'} +# steps: +# - name: Checkout +# uses: actions/checkout@v2 +# with: +# submodules: true +# - name: Install +# run: | +# sudo apt-add-repository ppa:mhier/libboost-latest +# sudo apt-get update +# sudo apt-get install boost1.70 +# if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then +# sudo apt-add-repository ppa:ubuntu-toolchain-r/test +# sudo apt-get update +# sudo apt-get install ${{ matrix.compiler }} +# fi +# - name: Configure +# run: | +# mkdir build && cd build +# if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then +# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON +# else +# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} +# fi +# - name: Build +# run: | +# cd build && cmake --build . +# - name: Test +# run: | +# cd build && ctest --output-on-failure +# build-linux-clang: +# runs-on: Ubuntu-18.04 +# strategy: +# matrix: +# compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] +# standard: ['11', '14', '17', '20'] +# exclude: +# - {compiler: '3.9', standard: '17'} +# - {compiler: '4.0', standard: '17'} +# - {compiler: '5.0', standard: '17'} +# - {compiler: '3.9', standard: '20'} +# - {compiler: '4.0', standard: '20'} +# - {compiler: '5.0', standard: '20'} +# - {compiler: '6.0', standard: '20'} +# - {compiler: '7', standard: '20'} +# steps: +# - name: Checkout +# uses: actions/checkout@v2 +# with: +# submodules: true +# - name: Install +# run: | +# sudo apt-add-repository ppa:mhier/libboost-latest +# sudo apt-get update +# sudo apt-get install boost1.70 +# if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then +# sudo apt-add-repository ppa:ubuntu-toolchain-r/test +# sudo apt-get update +# sudo apt-get install clang-${{ matrix.compiler }} +# fi +# - name: Configure +# run: | +# mkdir build && cd build +# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} +# - name: Build +# run: | +# cd build && cmake --build . +# - name: Test +# run: | +# cd build && ctest --output-on-failure + + build-osx: + runs-on: macos-10.15 strategy: matrix: - # g++-4.8 and 4.9 are tested on Travis.CI. - compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] standard: ['11', '14', '17', '20'] - exclude: - - {compiler: 'g++-5', standard: '17'} - - {compiler: 'g++-6', standard: '17'} - - {compiler: 'g++-5', standard: '20'} - - {compiler: 'g++-6', standard: '20'} - - {compiler: 'g++-7', standard: '20'} steps: - name: Checkout uses: actions/checkout@v2 @@ -23,104 +98,54 @@ jobs: submodules: true - name: Install run: | - sudo apt-add-repository ppa:mhier/libboost-latest - sudo apt-get update - sudo apt-get install boost1.70 - if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then - sudo apt-add-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install ${{ matrix.compiler }} - fi + brew install boost - name: Configure run: | mkdir build && cd build - if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then - cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON - else - cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} - fi + cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} - name: Build run: | cd build && cmake --build . - name: Test run: | cd build && ctest --output-on-failure - build-linux-clang: - runs-on: Ubuntu-18.04 - strategy: - matrix: - compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] - standard: ['11', '14', '17', '20'] - exclude: - - {compiler: '3.9', standard: '17'} - - {compiler: '4.0', standard: '17'} - - {compiler: '5.0', standard: '17'} - - {compiler: '3.9', standard: '20'} - - {compiler: '4.0', standard: '20'} - - {compiler: '5.0', standard: '20'} - - {compiler: '6.0', standard: '20'} - - {compiler: '7', standard: '20'} - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: true - - name: Install - run: | - sudo apt-add-repository ppa:mhier/libboost-latest - sudo apt-get update - sudo apt-get install boost1.70 - if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then - sudo apt-add-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install clang-${{ matrix.compiler }} - fi - - name: Configure - run: | - mkdir build && cd build - cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} - - name: Build - run: | - cd build && cmake --build . - - name: Test - run: | - cd build && ctest --output-on-failure - build-windows-msvc: - runs-on: windows-2019 - strategy: - matrix: - standard: ['11', '14', '17', '20'] - config: ['Release', 'Debug'] - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: true - - name: Install - run: | - (New-Object System.Net.WebClient).DownloadFile("https://github.com/actions/boost-versions/releases/download/1.72.0-20200608.4/boost-1.72.0-win32-msvc14.2-x86_64.tar.gz", "$env:TEMP\\boost.tar.gz") - 7z.exe x "$env:TEMP\\boost.tar.gz" -o"$env:TEMP\\boostArchive" -y | Out-Null - 7z.exe x "$env:TEMP\\boostArchive" -o"$env:TEMP\\boost" -y | Out-Null - Push-Location -Path "$env:TEMP\\boost" - Invoke-Expression .\\setup.ps1 - - uses: ilammy/msvc-dev-cmd@v1 - - name: Configure - shell: cmd - run: | - file --mime-encoding tests/test_literals.cpp - mkdir build - cd build - cmake ../ -G "NMake Makefiles" -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT="C:\\hostedtoolcache\\windows\\Boost\\1.72.0\\x86_64" - - name: Build - working-directory: ./build - run: | - cmake --build . --config "${{ matrix.config }}" - - name: Test - working-directory: ./build - run: | - ./tests/test_literals --log_level=all - file --mime-encoding tests/toml/tests/example.toml - file --mime-encoding tests/toml/tests/fruit.toml - file --mime-encoding tests/toml/tests/hard_example.toml - file --mime-encoding tests/toml/tests/hard_example_unicode.toml - ctest --build-config "${{ matrix.config }}" --output-on-failure + +# build-windows-msvc: +# runs-on: windows-2019 +# strategy: +# matrix: +# standard: ['11', '14', '17', '20'] +# config: ['Release', 'Debug'] +# steps: +# - name: Checkout +# uses: actions/checkout@v2 +# with: +# submodules: true +# - name: Install +# run: | +# (New-Object System.Net.WebClient).DownloadFile("https://github.com/actions/boost-versions/releases/download/1.72.0-20200608.4/boost-1.72.0-win32-msvc14.2-x86_64.tar.gz", "$env:TEMP\\boost.tar.gz") +# 7z.exe x "$env:TEMP\\boost.tar.gz" -o"$env:TEMP\\boostArchive" -y | Out-Null +# 7z.exe x "$env:TEMP\\boostArchive" -o"$env:TEMP\\boost" -y | Out-Null +# Push-Location -Path "$env:TEMP\\boost" +# Invoke-Expression .\\setup.ps1 +# - uses: ilammy/msvc-dev-cmd@v1 +# - name: Configure +# shell: cmd +# run: | +# file --mime-encoding tests/test_literals.cpp +# mkdir build +# cd build +# cmake ../ -G "NMake Makefiles" -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT="C:\\hostedtoolcache\\windows\\Boost\\1.72.0\\x86_64" +# - name: Build +# working-directory: ./build +# run: | +# cmake --build . --config "${{ matrix.config }}" +# - name: Test +# working-directory: ./build +# run: | +# ./tests/test_literals --log_level=all +# file --mime-encoding tests/toml/tests/example.toml +# file --mime-encoding tests/toml/tests/fruit.toml +# file --mime-encoding tests/toml/tests/hard_example.toml +# file --mime-encoding tests/toml/tests/hard_example_unicode.toml +# ctest --build-config "${{ matrix.config }}" --output-on-failure From 42cc111b059ab1fa793d9a98cbe3a5ccb203d7dc Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 25 Mar 2021 15:01:40 +0900 Subject: [PATCH 21/25] ci: activate linux/windows confirmed that macos works. --- .github/workflows/main.yml | 242 ++++++++++++++++++------------------- 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4e36ed9..c66ad87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,88 +3,88 @@ name: build on: [push, pull_request] jobs: -# build-linux-gcc: -# runs-on: Ubuntu-18.04 -# strategy: -# matrix: -# # g++-4.8 and 4.9 are tested on Travis.CI. -# compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] -# standard: ['11', '14', '17', '20'] -# exclude: -# - {compiler: 'g++-5', standard: '17'} -# - {compiler: 'g++-6', standard: '17'} -# - {compiler: 'g++-5', standard: '20'} -# - {compiler: 'g++-6', standard: '20'} -# - {compiler: 'g++-7', standard: '20'} -# steps: -# - name: Checkout -# uses: actions/checkout@v2 -# with: -# submodules: true -# - name: Install -# run: | -# sudo apt-add-repository ppa:mhier/libboost-latest -# sudo apt-get update -# sudo apt-get install boost1.70 -# if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then -# sudo apt-add-repository ppa:ubuntu-toolchain-r/test -# sudo apt-get update -# sudo apt-get install ${{ matrix.compiler }} -# fi -# - name: Configure -# run: | -# mkdir build && cd build -# if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then -# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON -# else -# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -# fi -# - name: Build -# run: | -# cd build && cmake --build . -# - name: Test -# run: | -# cd build && ctest --output-on-failure -# build-linux-clang: -# runs-on: Ubuntu-18.04 -# strategy: -# matrix: -# compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] -# standard: ['11', '14', '17', '20'] -# exclude: -# - {compiler: '3.9', standard: '17'} -# - {compiler: '4.0', standard: '17'} -# - {compiler: '5.0', standard: '17'} -# - {compiler: '3.9', standard: '20'} -# - {compiler: '4.0', standard: '20'} -# - {compiler: '5.0', standard: '20'} -# - {compiler: '6.0', standard: '20'} -# - {compiler: '7', standard: '20'} -# steps: -# - name: Checkout -# uses: actions/checkout@v2 -# with: -# submodules: true -# - name: Install -# run: | -# sudo apt-add-repository ppa:mhier/libboost-latest -# sudo apt-get update -# sudo apt-get install boost1.70 -# if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then -# sudo apt-add-repository ppa:ubuntu-toolchain-r/test -# sudo apt-get update -# sudo apt-get install clang-${{ matrix.compiler }} -# fi -# - name: Configure -# run: | -# mkdir build && cd build -# cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -# - name: Build -# run: | -# cd build && cmake --build . -# - name: Test -# run: | -# cd build && ctest --output-on-failure + build-linux-gcc: + runs-on: Ubuntu-18.04 + strategy: + matrix: + # g++-4.8 and 4.9 are tested on Travis.CI. + compiler: ['g++-9', 'g++-8', 'g++-7', 'g++-6', 'g++-5'] + standard: ['11', '14', '17', '20'] + exclude: + - {compiler: 'g++-5', standard: '17'} + - {compiler: 'g++-6', standard: '17'} + - {compiler: 'g++-5', standard: '20'} + - {compiler: 'g++-6', standard: '20'} + - {compiler: 'g++-7', standard: '20'} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install + run: | + sudo apt-add-repository ppa:mhier/libboost-latest + sudo apt-get update + sudo apt-get install boost1.70 + if [[ "${{ matrix.compiler }}" == "g++-6" || "${{ matrix.compiler }}" == "g++-5" ]] ; then + sudo apt-add-repository ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get install ${{ matrix.compiler }} + fi + - name: Configure + run: | + mkdir build && cd build + if [[ "${{ matrix.compiler }}" == "g++-8" && ( "${{ matrix.standard }}" == "17" || "${{ matrix.standard }}" == "20" ) ]] ; then + cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DTOML11_REQUIRE_FILESYSTEM_LIBRARY=ON + else + cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_COMPILER=${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} + fi + - name: Build + run: | + cd build && cmake --build . + - name: Test + run: | + cd build && ctest --output-on-failure + build-linux-clang: + runs-on: Ubuntu-18.04 + strategy: + matrix: + compiler: ['10', '9', '8', '7', '6.0', '5.0', '4.0', '3.9'] + standard: ['11', '14', '17', '20'] + exclude: + - {compiler: '3.9', standard: '17'} + - {compiler: '4.0', standard: '17'} + - {compiler: '5.0', standard: '17'} + - {compiler: '3.9', standard: '20'} + - {compiler: '4.0', standard: '20'} + - {compiler: '5.0', standard: '20'} + - {compiler: '6.0', standard: '20'} + - {compiler: '7', standard: '20'} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install + run: | + sudo apt-add-repository ppa:mhier/libboost-latest + sudo apt-get update + sudo apt-get install boost1.70 + if [[ "${{ matrix.compiler }}" != "6" && "${{ matrix.compiler }}" != "8" && "${{ matrix.compiler }}" != "9" ]] ; then + sudo apt-add-repository ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get install clang-${{ matrix.compiler }} + fi + - name: Configure + run: | + mkdir build && cd build + cmake .. -Dtoml11_BUILD_TEST=ON -DCMAKE_C_COMPILER=clang-${{ matrix.compiler }} -DCMAKE_CXX_COMPILER=clang++-${{ matrix.compiler }} -DCMAKE_CXX_STANDARD=${{ matrix.standard }} + - name: Build + run: | + cd build && cmake --build . + - name: Test + run: | + cd build && ctest --output-on-failure build-osx: runs-on: macos-10.15 @@ -110,42 +110,42 @@ jobs: run: | cd build && ctest --output-on-failure -# build-windows-msvc: -# runs-on: windows-2019 -# strategy: -# matrix: -# standard: ['11', '14', '17', '20'] -# config: ['Release', 'Debug'] -# steps: -# - name: Checkout -# uses: actions/checkout@v2 -# with: -# submodules: true -# - name: Install -# run: | -# (New-Object System.Net.WebClient).DownloadFile("https://github.com/actions/boost-versions/releases/download/1.72.0-20200608.4/boost-1.72.0-win32-msvc14.2-x86_64.tar.gz", "$env:TEMP\\boost.tar.gz") -# 7z.exe x "$env:TEMP\\boost.tar.gz" -o"$env:TEMP\\boostArchive" -y | Out-Null -# 7z.exe x "$env:TEMP\\boostArchive" -o"$env:TEMP\\boost" -y | Out-Null -# Push-Location -Path "$env:TEMP\\boost" -# Invoke-Expression .\\setup.ps1 -# - uses: ilammy/msvc-dev-cmd@v1 -# - name: Configure -# shell: cmd -# run: | -# file --mime-encoding tests/test_literals.cpp -# mkdir build -# cd build -# cmake ../ -G "NMake Makefiles" -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT="C:\\hostedtoolcache\\windows\\Boost\\1.72.0\\x86_64" -# - name: Build -# working-directory: ./build -# run: | -# cmake --build . --config "${{ matrix.config }}" -# - name: Test -# working-directory: ./build -# run: | -# ./tests/test_literals --log_level=all -# file --mime-encoding tests/toml/tests/example.toml -# file --mime-encoding tests/toml/tests/fruit.toml -# file --mime-encoding tests/toml/tests/hard_example.toml -# file --mime-encoding tests/toml/tests/hard_example_unicode.toml -# ctest --build-config "${{ matrix.config }}" --output-on-failure + build-windows-msvc: + runs-on: windows-2019 + strategy: + matrix: + standard: ['11', '14', '17', '20'] + config: ['Release', 'Debug'] + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + - name: Install + run: | + (New-Object System.Net.WebClient).DownloadFile("https://github.com/actions/boost-versions/releases/download/1.72.0-20200608.4/boost-1.72.0-win32-msvc14.2-x86_64.tar.gz", "$env:TEMP\\boost.tar.gz") + 7z.exe x "$env:TEMP\\boost.tar.gz" -o"$env:TEMP\\boostArchive" -y | Out-Null + 7z.exe x "$env:TEMP\\boostArchive" -o"$env:TEMP\\boost" -y | Out-Null + Push-Location -Path "$env:TEMP\\boost" + Invoke-Expression .\\setup.ps1 + - uses: ilammy/msvc-dev-cmd@v1 + - name: Configure + shell: cmd + run: | + file --mime-encoding tests/test_literals.cpp + mkdir build + cd build + cmake ../ -G "NMake Makefiles" -Dtoml11_BUILD_TEST=ON -DCMAKE_CXX_STANDARD=${{ matrix.standard }} -DBoost_NO_BOOST_CMAKE=ON -DBOOST_ROOT="C:\\hostedtoolcache\\windows\\Boost\\1.72.0\\x86_64" + - name: Build + working-directory: ./build + run: | + cmake --build . --config "${{ matrix.config }}" + - name: Test + working-directory: ./build + run: | + ./tests/test_literals --log_level=all + file --mime-encoding tests/toml/tests/example.toml + file --mime-encoding tests/toml/tests/fruit.toml + file --mime-encoding tests/toml/tests/hard_example.toml + file --mime-encoding tests/toml/tests/hard_example_unicode.toml + ctest --build-config "${{ matrix.config }}" --output-on-failure From 17a15d3c18f25f96ea2eed38519d90809ce40171 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 25 Mar 2021 22:33:05 +0900 Subject: [PATCH 22/25] doc: update contributor list and link in README --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2ce9e3..06cd511 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ toml11 toml11 is a C++11 (or later) header-only toml parser/encoder depending only on C++ standard library. -- It is compatible to the latest version of [TOML v1.0.0-rc.2](https://toml.io/en/v1.0.0-rc.2). +- It is compatible to the latest version of [TOML v1.0.0](https://toml.io/en/v1.0.0). - It is one of the most TOML standard compliant libraries, tested with [the language agnostic test suite for TOML parsers by BurntSushi](https://github.com/BurntSushi/toml-test). - It shows highly informative error messages. You can see the error messages about invalid files at [CircleCI](https://circleci.com/gh/ToruNiina/toml11). - It has configurable container. You can use any random-access containers and key-value maps as backend containers. @@ -1873,6 +1873,12 @@ I appreciate the help of the contributors who introduced the great feature to th - Fix include path in README - Mohammed Alyousef (@MoAlyousef) - Made testing optional in CMake +- Ivan Shynkarenka (@chronoxor) + - Fix compilation error in `` with MinGW +- Alex Merry (@amerry) + - Add missing include files +- sneakypete81 (@sneakypete81) + - Fix typo in error message ## Licensing terms From 5e3f8f910535a9b6670f1f86be2d8c03801899d2 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 25 Mar 2021 22:43:37 +0900 Subject: [PATCH 23/25] chore: update version values --- CMakeLists.txt | 2 +- toml.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dbeb2b..c0be74b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.1) enable_testing() -project(toml11 VERSION 3.6.0) +project(toml11 VERSION 3.6.1) option(toml11_BUILD_TEST "Build toml tests" OFF) option(toml11_TEST_WITH_ASAN "use LLVM address sanitizer" OFF) diff --git a/toml.hpp b/toml.hpp index 232329d..e989798 100644 --- a/toml.hpp +++ b/toml.hpp @@ -35,7 +35,7 @@ #define TOML11_VERSION_MAJOR 3 #define TOML11_VERSION_MINOR 6 -#define TOML11_VERSION_PATCH 0 +#define TOML11_VERSION_PATCH 1 #include "toml/parser.hpp" #include "toml/literal.hpp" From c121492071373a497a1477ea6855a2814de16039 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 29 Mar 2021 17:48:03 +0900 Subject: [PATCH 24/25] fix: uneven spacing between tables related: issue #152 --- toml/serializer.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index bef1827..2442ed9 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -582,6 +582,7 @@ struct serializer std::find(tmp.cbegin(), tmp.cend(), '\n') != tmp.cend()) { multiline_table_printed = true; + tmp += '\n'; } else { From a3b8dd678726dcc4b32d42929d65c53e3ecdd856 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 31 Mar 2021 10:52:18 +0900 Subject: [PATCH 25/25] fix(#152): add newline btw kv-pair and subtables --- toml/serializer.hpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index 2442ed9..77aef58 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -578,20 +578,35 @@ struct serializer !multiline_table_printed, this->no_comment_, ks, /*has_comment*/ !kv.second.comments().empty()), kv.second); + // If it is the first time to print a multi-line table, it would be + // helpful to separate normal key-value pair and subtables by a + // newline. + // (this checks if the current key-value pair contains newlines. + // but it is not perfect because multi-line string can also contain + // a newline. in such a case, an empty line will be written) TODO if((!multiline_table_printed) && std::find(tmp.cbegin(), tmp.cend(), '\n') != tmp.cend()) { multiline_table_printed = true; - tmp += '\n'; + token += '\n'; // separate key-value pairs and subtables + + token += write_comments(kv.second); + token += tmp; + + // care about recursive tables (all tables in each level prints + // newline and there will be a full of newlines) + if(tmp.substr(tmp.size() - 2, 2) != "\n\n" && + tmp.substr(tmp.size() - 4, 4) != "\r\n\r\n" ) + { + token += '\n'; + } } else { - // still inline tables only. - tmp += '\n'; + token += write_comments(kv.second); + token += tmp; + token += '\n'; } - - token += write_comments(kv.second); - token += tmp; } return token; }