i try split following text:
std::string text="1,2,3,max(4,5,6,7),array[8,9],10,page{11,12},13";
i have following code:
std::vector<std::string> found_list; boost::split(found_list,text,boost::is_any_of(","))
but desired output is:
1 2 3 max(4,5,6,7) array[8,9] 10 page{11,12} 13
regarding parentheses , braces, how implement it?
you want parse grammar.
since tagged boost let me show using boost spirit:
#include <boost/spirit/include/qi.hpp> namespace qi = boost::spirit::qi; int main() { std::string const text="1,2,3,max(4,5,6,7),array[8,9],10,page{11,12},13"; std::vector<std::string> split; if (qi::parse(text.begin(), text.end(), qi::raw [ qi::int_ | +qi::alnum >> ( '(' >> *~qi::char_(')') >> ')' | '[' >> *~qi::char_(']') >> ']' | '{' >> *~qi::char_('}') >> '}' ) ] % ',', split)) { (auto& item : split) std::cout << item << "\n"; } }
prints
1 2 3 max(4,5,6,7) array[8,9] 10 page{11,12} 13
Comments
Post a Comment