Boost logo

Boost :

From: SourceForge.net (noreply_at_[hidden])
Date: 2006-02-17 03:54:36


Bugs item #1433424, was opened at 2006-02-17 00:54
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1433424&group_id=7586

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: program_options: additional parser bug

Initial Comment:
alexander.kondratyuk_at_[hidden]
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;
}

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1433424&group_id=7586

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Boost-bugs mailing list
Boost-bugs_at_[hidden]
https://lists.sourceforge.net/lists/listinfo/boost-bugs


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk