0

While going through the documentation I read that

for a string of doubles separated by a comma we could go like this (which I understand)

double_ >> * (',' >> double_) or double_ %

but what does the following expression mean. Its supposed to split comma separated strings into a vector and it works. I would appreciate it if someone could kindly clarify it. I am confused with - operator I believe its a difference operator but I cant figure out its role here

*(qi::char_ - ',') % ','

Rajeshwar
  • 11,179
  • 26
  • 86
  • 158

3 Answers3

5

*(char_ - ',') means "match zero or more characters but ','", and it can also be written like this: *~char_(","). On the other hand, *char_ means just "match zero or more characters".

To understand, why the exclusion is needed, just try with and without it:

#include <string>
#include <boost/spirit/home/qi.hpp>
int main()
{
    using namespace boost::spirit::qi;
    std::vector<std::string> out1, out2;
    std::string s = "str1, str2, str3";
    bool b = parse(s.begin(), s.end(), *~char_(",") % ",", out1); // out1: ["str1", "str2", "str3"]
    b = parse(s.begin(), s.end(), *char_ % ",", out2); // out2: ["str1, str2, str3"]
}
Igor R.
  • 14,716
  • 2
  • 49
  • 83
0

qi::char_ - ',' matches all characters but , to prevent the inner expression from being too greedy.

filmor
  • 30,840
  • 6
  • 50
  • 48
0

You really need to read EBNF standard to understand Boost.Spirit.