Parsing string, with Boost Spirit 2, to fill data in user defined struct

Posted by Surya on Stack Overflow See other posts from Stack Overflow or by Surya
Published on 2010-03-18T12:47:07Z Indexed on 2010/03/18 12:51 UTC
Read the original article Hit count: 462

I'm using Boost.Spirit which was distributed with Boost-1.42.0 with VS2005. My problem is like this.

I've this string which was delimted with commas. The first 3 fields of it are strings and rest are numbers. like this.

String1,String2,String3,12.0,12.1,13.0,13.1,12.4

My rule is like this

qi::rule<string::iterator, qi::skip_type> stringrule = *(char_ - ',')
qi::rule<string::iterator, qi::skip_type> myrule= repeat(3)[*(char_ - ',') >> ','] >> (double_ % ',') ;

I'm trying to store the data in a structure like this.

struct MyStruct
{
   vector<string> stringVector ;
   vector<double> doubleVector ;
} ;

MyStruct var ;

I've wrapped it in BOOST_FUSION_ADAPT_STRUCTURE to use it with spirit.

BOOST_FUSION_ADAPT_STRUCT (MyStruct, (vector<string>, stringVector) (vector<double>, doubleVector))

My parse function parses the line and returns true and after

qi::phrase_parse (iterBegin, iterEnd, myrule, boost::spirit::ascii::space, var) ;

I'm expecting var.stringVector and var.doubleVector are properly filled. but it is not the case.

What is going wrong ?

Thanks in advance, Surya

© Stack Overflow or respective owner

Related posts about boost-spirit

Related posts about boost-spirit-qi