diff --git a/include/CLI/Config.hpp b/include/CLI/Config.hpp index 5a982236..0f6a05a7 100644 --- a/include/CLI/Config.hpp +++ b/include/CLI/Config.hpp @@ -211,7 +211,11 @@ inline std::vector ConfigBase::from_config(std::istream &input) cons if(pos != std::string::npos) { name = detail::trim_copy(line.substr(0, pos)); std::string item = detail::trim_copy(line.substr(pos + 1)); - if(item.size() > 1 && item.front() == aStart && item.back() == aEnd) { + if(item.size() > 1 && item.front() == aStart) { + for(std::string multiline; item.back() != aEnd && std::getline(input, multiline);) { + detail::trim(multiline); + item += multiline; + } items_buffer = detail::split_up(item.substr(1, item.length() - 2), aSep); } else if((isDefaultArray || isINIArray) && item.find_first_of(aSep) != std::string::npos) { items_buffer = detail::split_up(item, aSep); diff --git a/tests/ConfigFileTest.cpp b/tests/ConfigFileTest.cpp index 590eb6b6..d8b19d14 100644 --- a/tests/ConfigFileTest.cpp +++ b/tests/ConfigFileTest.cpp @@ -150,6 +150,47 @@ TEST(StringBased, Vector) { EXPECT_EQ("seven", output.at(2).inputs.at(2)); } +TEST(StringBased, TomlVector) { + std::stringstream ofile; + + ofile << "one = [three]\n"; + ofile << "two = [four]\n"; + ofile << "five = [six, and, seven]\n"; + ofile << "eight = [nine, \n" + "ten, eleven, twelve \n" + "]\n"; + ofile << "one_more = [one, \n" + "two, three ] \n"; + + ofile.seekg(0, std::ios::beg); + + std::vector output = CLI::ConfigINI().from_config(ofile); + + EXPECT_EQ(5u, output.size()); + EXPECT_EQ("one", output.at(0).name); + EXPECT_EQ(1u, output.at(0).inputs.size()); + EXPECT_EQ("three", output.at(0).inputs.at(0)); + EXPECT_EQ("two", output.at(1).name); + EXPECT_EQ(1u, output.at(1).inputs.size()); + EXPECT_EQ("four", output.at(1).inputs.at(0)); + EXPECT_EQ("five", output.at(2).name); + EXPECT_EQ(3u, output.at(2).inputs.size()); + EXPECT_EQ("six", output.at(2).inputs.at(0)); + EXPECT_EQ("and", output.at(2).inputs.at(1)); + EXPECT_EQ("seven", output.at(2).inputs.at(2)); + EXPECT_EQ("eight", output.at(3).name); + EXPECT_EQ(4u, output.at(3).inputs.size()); + EXPECT_EQ("nine", output.at(3).inputs.at(0)); + EXPECT_EQ("ten", output.at(3).inputs.at(1)); + EXPECT_EQ("eleven", output.at(3).inputs.at(2)); + EXPECT_EQ("twelve", output.at(3).inputs.at(3)); + EXPECT_EQ("one_more", output.at(4).name); + EXPECT_EQ(3u, output.at(4).inputs.size()); + EXPECT_EQ("one", output.at(4).inputs.at(0)); + EXPECT_EQ("two", output.at(4).inputs.at(1)); + EXPECT_EQ("three", output.at(4).inputs.at(2)); +} + TEST(StringBased, Spaces) { std::stringstream ofile;