diff --git a/include/CLI/StringTools.hpp b/include/CLI/StringTools.hpp index 4a035b323..87af9d937 100644 --- a/include/CLI/StringTools.hpp +++ b/include/CLI/StringTools.hpp @@ -220,9 +220,6 @@ CLI11_INLINE std::vector split_up(std::string str, char delimiter = /// the return value is the offset+1 which is required by the find_and_modify function. CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset); -/// Add quotes if the string contains spaces -CLI11_INLINE std::string &add_quotes_if_needed(std::string &str); - /// get the value of an environmental variable or empty string if empty CLI11_INLINE std::string get_environment_value(const std::string &env_name); } // namespace detail diff --git a/include/CLI/impl/StringTools_inl.hpp b/include/CLI/impl/StringTools_inl.hpp index fd3dcc2ff..e5761c238 100644 --- a/include/CLI/impl/StringTools_inl.hpp +++ b/include/CLI/impl/StringTools_inl.hpp @@ -244,17 +244,6 @@ CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset) { return offset + 1; } -CLI11_INLINE std::string &add_quotes_if_needed(std::string &str) { - if((str.front() != '"' && str.front() != '\'') || str.front() != str.back()) { - char quote = str.find('"') < str.find('\'') ? '\'' : '"'; - if(str.find(' ') != std::string::npos) { - str.insert(0, 1, quote); - str.append(1, quote); - } - } - return str; -} - std::string get_environment_value(const std::string &env_name) { char *buffer = nullptr; std::string ename_string; diff --git a/include/CLI/impl/Validators_inl.hpp b/include/CLI/impl/Validators_inl.hpp index a2295ecdf..1332e55ef 100644 --- a/include/CLI/impl/Validators_inl.hpp +++ b/include/CLI/impl/Validators_inl.hpp @@ -135,7 +135,7 @@ CLI11_INLINE path_type check_path(const char *file) noexcept { switch(stat.type()) { case std::filesystem::file_type::none: // LCOV_EXCL_LINE case std::filesystem::file_type::not_found: - return path_type::nonexistent; + return path_type::nonexistent; // LCOV_EXCL_LINE case std::filesystem::file_type::directory: return path_type::directory; case std::filesystem::file_type::symlink: diff --git a/tests/AppTest.cpp b/tests/AppTest.cpp index 386418d49..8e5d57f27 100644 --- a/tests/AppTest.cpp +++ b/tests/AppTest.cpp @@ -1101,6 +1101,42 @@ TEST_CASE_METHOD(TApp, "emptyVectorReturn", "[app]") { CHECK_FALSE(strs3.empty()); } +TEST_CASE_METHOD(TApp, "emptyVectorReturnReduce", "[app]") { + + std::vector strs; + std::vector strs2; + std::vector strs3; + auto *opt1 = app.add_option("--str", strs)->required()->expected(0, 2); + app.add_option("--str3", strs3)->expected(1, 3); + app.add_option("--str2", strs2)->expected(1, 1)->take_first(); + args = {"--str"}; + + CHECK_NOTHROW(run()); + CHECK(std::vector({""}) == strs); + args = {"--str", "one", "two"}; + + run(); + + CHECK(std::vector({"one", "two"}) == strs); + + args = {"--str", "{}", "--str2", "{}", "test"}; + + run(); + + CHECK(strs.empty()); + CHECK(std::vector{"{}"} == strs2); + opt1->default_str("{}"); + args = {"--str"}; + + CHECK_NOTHROW(run()); + CHECK(strs.empty()); + opt1->required(false); + args = {"--str3", "{}"}; + + CHECK_NOTHROW(run()); + CHECK_FALSE(strs3.empty()); +} + TEST_CASE_METHOD(TApp, "RequiredOptsDoubleShort", "[app]") { std::vector strs;