Opened 17 years ago
Closed 16 years ago
#564 closed Bugs (Fixed)
program_options: additional parser bug
| Reported by: | nobody | Owned by: | Vladimir Prus |
|---|---|---|---|
| Milestone: | Component: | None | |
| Version: | None | Severity: | |
| Keywords: | Cc: |
Description
alexander.kondratyuk@gmail.com
It seems there is a bug in additional parser wrapper -
in case then my option has no parameters defined and
declared in description, it adds an empty value to
the vector of values when additional paser returns
pair of strings.
Changing code in cmdline.cpp in function
cmdline::handle_additional_parser
from
next.value.push_back(r.second);
to
if (!r.second.empty())
next.value.push_back(r.second);
will fix the problem.
Here is an example that illustrates the problem:
#define BOOST_WHATEVER_DYN_LINK
#define BOOST_LIB_DIAGNOSTIC
#include <boost/program_options/variables_map.hpp>
#include
<boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include
<boost/program_options/detail/utf8_codecvt_facet.hpp>
#include <boost/token_iterator.hpp>
#include <boost/shared_ptr.hpp>
using namespace boost::program_options;
#include <string>
#include <vector>
using namespace std;
pair<string, string> parserDashDashShort(const
string& s)
{
string str = s.substr( 0, s.find('=') );
if( str.length()==3 && str[0]=='-' && str[1]=='-'
&& str[2]<='z' && str[2]>='a')
{
string val = s.substr(str.length());
return make_pair( str.substr(1), val );
}
return make_pair(string(), string());
}
int _tmain(int , _TCHAR* argv[])
{
int style =
command_line_style::allow_short|
command_line_style::allow_dash_for_short |
command_line_style::short_allow_adjacent;
options_description desc;
desc.add_options()
("help,h", "help message")
;
char* args[]={"program.exe", "--h"};
int argc = sizeof( args ) / sizeof( args[0] );
parse_command_line<char>( argc, (char**)args,
desc, style, parserDashDashShort );
return 0;
}
Note:
See TracTickets
for help on using tickets.
