How can I extract std :: string with boost.spirit?

Using boost.spirit, I am trying to parse a simple form command line command:param1 param2...

To do this, I created this parser:

(+(char_ - ':'))[ref(cmd) = _1]
>> ':'
>> (*char_)[ref(params) = _1]

The parser attribute types of the two components are vectors, so if cmd and params are type vectors, this is the job. However, if they are of type std :: string, this is not so. When searching for this solution on the Internet, I found a hint that it should also work with the string. Anyway, can I do this work with string?

+3
source share
1 answer

, . (+(char_ - ':') *char_) std::vector<char> . _1 a std::vector<char>. cmd params std::string, , std::vector<char> std::string.

, , :

std::string s("command:param1 param2");
std::string cmd, params;
parse(s.begin(), s.end(), +~char_(':') >> ':' >> *char_, cmd, params);

, . .

+6

Source: https://habr.com/ru/post/1770433/


All Articles