我的情况:我是 Spirit 的新手,我必须使用 VC6,因此我使用的是 Spirit 1.6.4。
我有一条看起来像这样的线:
//The Description;DESCRIPTION;;
DESCRIPTION
如果行以 . 开头,我想将文本放入字符串中//The Description;
。
我有一些有用的东西,但对我来说看起来并不那么优雅:
vector<char> vDescription; // std::string doesn't work due to missing ::clear() in VC6's STL implementation
if(parse(chars,
// Begin grammar
(
as_lower_d["//the description;"]
>> (+~ch_p(';'))[assign(vDescription)]
),
// End grammar
space_p).hit)
{
const string desc(vDescription.begin(), vDescription.end());
}
我更想将所有可打印字符分配到下一个';'
,但以下不起作用,因为parse(...).hit == false
parse(chars,
// Begin grammar
(
as_lower_d["//the description;"]
>> (+print_p)[assign(vDescription)]
>> ';'
),
// End grammar
space_p).hit)
我如何让它击中?