« Return to Thread: [qi] order of aleternatives

Re: [qi] order of aleternatives

by Hartmut Kaiser :: Rate this Message:

Reply to Author | View in Thread

> Carl Barron wrote:
> > I thougt    x =  a | b | c | d ;  would do
> >
> > if a matches  then  match found
> > else if b matches then match found
> > else if c matches then match found
> > else if d matches then match found
> > else match not found
> >
> > How ever integere in attached code appears to test zero (last
> > alternative) first, is this a bug
> > or a feature??   All integer is supposed to do is determine base and
> > convert text to a 32 bit unsigned integer,   This is a simple qi
> parser
> > of ipv4_addresses no lex.
>
> Hmmm.. Looks like a bug indeed :(.
> Can you simplify the code to a minimum test case?

It's not a bug. These are wrong:

    qi::uint_parser<uint32_t,16,-1,-1>  hex_int;
    qi::uint_parser<uint32_t,8,-1,-1>  octal_int;

The third template arguments are treated as unsigned ints, which requests
matching of at least (uint)(-1) digits, which is clearly not the desired
functionality. Change that to:

    qi::uint_parser<uint32_t,16,1,-1>  hex_int;
    qi::uint_parser<uint32_t,8,1,-1>  octal_int;

or just

    qi::uint_parser<uint32_t,16>  hex_int;
    qi::uint_parser<uint32_t,8>  octal_int;

or even simpler, just use the predefined parsers 'hex' and 'oct' instead.
Then everything works as expected.

Regards Hartmut


>
> Regards,
> --
> Joel de Guzman
> http://www.boostpro.com
> http://spirit.sf.net
>
>
> -----------------------------------------------------------------------
> -------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited
> time,
> vendors submitting new applications to BlackBerry App World(TM) will
> have
> the opportunity to enter the BlackBerry Developer Challenge. See full
> prize
> details at: http://p.sf.net/sfu/Challenge
> _______________________________________________
> Spirit-general mailing list
> Spirit-general@...
> https://lists.sourceforge.net/lists/listinfo/spirit-general


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

 « Return to Thread: [qi] order of aleternatives