mirror of
https://github.com/boostorg/program_options.git
synced 2026-01-19 04:22:15 +00:00
Changed defaults for split_unix() function to be more compliant to unix command line style
[SVN r58134]
This commit is contained in:
@@ -210,14 +210,14 @@ namespace boost { namespace program_options {
|
||||
and escape characters '\'
|
||||
*/
|
||||
BOOST_PROGRAM_OPTIONS_DECL std::vector<std::string>
|
||||
split_unix(const std::string& cmdline, const std::string& seperator = " ",
|
||||
const std::string& quote = "\"", const std::string& escape = "\\");
|
||||
split_unix(const std::string& cmdline, const std::string& seperator = " \t",
|
||||
const std::string& quote = "'\"", const std::string& escape = "\\");
|
||||
|
||||
#ifndef BOOST_NO_STD_WSTRING
|
||||
/** @overload */
|
||||
BOOST_PROGRAM_OPTIONS_DECL std::vector<std::wstring>
|
||||
split_unix(const std::wstring& cmdline, const std::wstring& seperator = L" ",
|
||||
const std::wstring& quote = L"\"", const std::wstring& escape = L"\\");
|
||||
split_unix(const std::wstring& cmdline, const std::wstring& seperator = L" \t",
|
||||
const std::wstring& quote = L"'\"", const std::wstring& escape = L"\\");
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -148,6 +148,26 @@ void split_single_quote(const options_description& description)
|
||||
notify(vm);
|
||||
}
|
||||
|
||||
void split_defaults(const options_description& description)
|
||||
{
|
||||
const char* cmdline = "prg --input \t \'input file.txt\' \t --optimization 4 --opt \\\"option1\\ option2\\\"";
|
||||
|
||||
vector< string > tokens = split_unix(cmdline);
|
||||
|
||||
BOOST_REQUIRE(tokens.size() == 7);
|
||||
check_value(tokens[0], "prg");
|
||||
check_value(tokens[1], "--input");
|
||||
check_value(tokens[2], "input file.txt");
|
||||
check_value(tokens[3], "--optimization");
|
||||
check_value(tokens[4], "4");
|
||||
check_value(tokens[5], "--opt");
|
||||
check_value(tokens[6], "\"option1 option2\"");
|
||||
|
||||
variables_map vm;
|
||||
store(command_line_parser(tokens).options(description).run(), vm);
|
||||
notify(vm);
|
||||
}
|
||||
|
||||
int main(int /*ac*/, char** /*av*/)
|
||||
{
|
||||
options_description desc;
|
||||
@@ -163,6 +183,7 @@ int main(int /*ac*/, char** /*av*/)
|
||||
split_quotes(desc);
|
||||
split_escape(desc);
|
||||
split_single_quote(desc);
|
||||
split_defaults(desc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user