我想解析字符串解析字符串的boost ::精神phrase_parse
std::string entry = "127.0.0.1 - [16/Aug/2012:01:50:02 +0000] \"GET /check.htm HTTP/1.1\" 200 17 \"AgentName/0.1 libwww-perl/5.833\""
與如下:
ip_rule %= lexeme[(+char_("0-9."))[ref(ip) = _1]];
timestamp_rule %= lexeme[('[' >> +(char_ - ']') >> ']')[ref(timestamp) = _1]];
user_rule %= lexeme[(+char_)[ref(user) = _1]];
request_rule %= lexeme[('"' >> +(char_ - '"') >> '"')[ref(req) = _1]];
referer_rule %= lexeme[('"' >> +(char_ - '"') >> '"')[ref(referer) = _1]];
bool r = phrase_parse(first, last,
ip_rule >> user_rule >> timestamp_rule >> request_rule >> uint_[ref(status) = _1]
>> uint_[ref(transferred_bytes) = _1] >> referer_rule, space);
,但它不匹配。如果我從字符串中刪除了「 - 」,當然還有規則「user_rule」,而不是匹配。您能否建議如何將字符串與「 - 」匹配?
規則具有以下類型: 規則<迭代器,的std :: string(),空間類型> ip_rule,timestamp_rule,user_rule,request_rule,referer_rule; – bayerb