1
#include <iostream>
#include <boost/spirit/include/qi.hpp>

namespace qi = boost::spirit::qi;
int main ()
{
    std::string input("   aaa   ");
    std::string::iterator strbegin = input.begin();
    std::string p;
    qi::phrase_parse(strbegin, input.end(),
            qi::lexeme[+qi::char_],
            qi::space,                  
            p);                               

    std::cout << p << std::endl;
    std::cout << p.size() << std::endl;
}

In this code parser assigns "aaa " to p. Why doesn't it skip all spaces? I expect p to be "aaa". How it can be fixed?

Ashot
  • 10,807
  • 14
  • 66
  • 117

1 Answers1

3

You are asking Spirit to emit the spaces with qi::lexeme. Compare: http://www.boost.org/doc/libs/1_55_0/libs/spirit/doc/html/spirit/qi/reference/directive/lexeme.html

The rule +(qi::char_ - qi::space) should do.

Mike M
  • 2,263
  • 3
  • 17
  • 31
  • 1
    Many more options to control skipping are described here http://stackoverflow.com/a/10469726/85371. Also, `qi::graph` should be equivalent to `char_ - space` AFAIR – sehe Feb 22 '14 at 21:47