Boost logo

Boost Users :

Subject: Re: [Boost-users] tokenize string delimiter
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2010-02-12 04:18:57


On Thu, Feb 11, 2010 at 10:53 PM, Matthias Vallentin
<vallentin_at_[hidden]> wrote:
> On Thu, Feb 11, 2010 at 03:22:53PM -0700, OvermindDL1 wrote:
>>     std::string result;
>>     parse(str.begin(),str.end(), raw[+~char_(delim)]%lit(delim), result);
>
> This fails in the first argument of qi::parse:
>
>    using boost::spirit::qi::lit;
>    using boost::spirit::qi::raw;
>    using boost::spirit::qi::string;
>
>    std::string str("foo---bar---baz");
>    std::string delim("---");
>    std::string result;
>    boost::spirit::qi::parse(str.begin(), str.end(),
>            raw[+~string(delim)] % lit(delim), result);
>
> Any ideas why?

If you are using GCC (which is actually doing things correctly, the
above code works on MSVC, which is not quite correct, but this code
works everywhere), then do this for the parse line instead:
    std::string::const_iterator iter=str.begin(),iterEnd=str.end();
  Â  boost::spirit::qi::parse(iter, iterEnd,
 Â           raw[+~string(delim)] % lit(delim), result);

On Thu, Feb 11, 2010 at 8:17 PM, Rob Riggs <rob_at_[hidden]> wrote:
> On 02/11/2010 03:22 PM, OvermindDL1 wrote:
>>
>> You can do that off the bat using Boost.Spirit2.1+ like this:
>> Or case insensitive:
>>
>>     parse(str.begin(),str.end(),
>> nocase[raw[+~char_(delim)]%lit(delim)], result);
>>
>> And there is *SO*MUCH* more you can do with spirit too, and it
>> executes faster then the tokanizer and such as well, while working on
>> input iterators, etc...
>>
>
> Spirit seems to have the same operator-overloaded "write-only code" quality
> that Perl suffers from.  The implementation may be the greatest thing ever,
> but the end result is a bit worrisome.  The string algorithm library's
> syntax is far more reasonable IMO.

Not sure of what you speak, I cannot think of any better way to
implement anything as powerful as Spirit within the confines of the
C++ language without becoming *exceedingly* long and impossible to
read... How is the string algorithm libraries syntax better? It is
slower and cannot do anywhere near as much (Spirit is a full PEG
parser).


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net