Boost split 不遍历括号或大括号内部

Boost split not traversing inside of parenthesis or braces

我尝试拆分以下文本:

std::string text="1,2,3,max(4,5,6,7),array[8,9],10,page{11,12},13";

我有以下代码:

std::vector<std::string> found_list;
boost::split(found_list,text,boost::is_any_of(","))

但我想要的输出是:

1
2
3
max(4,5,6,7)
array[8,9]
10
page{11,12}
13

关于圆括号和大括号,如何实现?

您想解析一个语法

既然你用 标记了,让我向你展示如何使用 Boost Spirit:

Live On Coliru

#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))
    {
        for (auto& item : split)
            std::cout << item << "\n";
    }
}

版画

1
2
3
max(4,5,6,7)
array[8,9]
10
page{11,12}
13