【发布时间】:2012-05-24 07:02:21
【问题描述】:
我编写了一个解析器来查找字符串连接表达式。我有一系列用括号括起来的字符串,主要来自函数调用。
例如("one"+"two"+"three") -> ("one"|"two"|"three")是一个简单的案例,我可以处理。
更困难的情况是(null, "one"+"two"+"three", null) -> (null, "one"|"two"|"three", null),但我可以用boost::tokenizer 解析它。
(null, "one"+"two"+"three,four", 1 /* third parameter can be: 1, 2, 3 */),在这样一个困难的例子中,我建议使用boost::spirit 进行解析,但我需要帮助来为其编写一些规则。
稍后:
似乎boost::tokenizer 中的escaped_list_separator 是我需要的。
但我有一个问题:
using namespace std;
using namespace boost;
string s = "Field 1,\"putting quotes around fields, allows commas\",Field 3";
tokenizer<escaped_list_separator<char> > tok(s,escaped_list_separator<char>("", ",", "\""));
for(tokenizer<escaped_list_separator<char> >::iterator beg=tok.begin(); beg!=tok.end();++beg){
cout <<"~~~"<< *beg << "\n";
}
为我删除 "。可以像这样在输出中保留引号
Field 1
"putting quotes around fields, allows commas"
Field 3
【问题讨论】:
标签: c++ boost boost-spirit