使用替代解析器增强Spirit替代解析器的空值处理

时间:2019-01-10 06:51:26

标签: boost-spirit

我正在尝试解析字符串

  

“ AAPL,1,P,〜,,,,,〜,P”

使用以下解析器

qi::rule<std::string::iterator, uint64_t()>
m_fixed_point = int_part[qi::_val =  qi::_1 * PRICE_MULT] >>
    -("." >> -(m_digit[qi::_val += qi::_1 * 1000])
          >> -(m_digit[qi::_val += qi::_1 * 100])
          >> -(m_digit[qi::_val += qi::_1 * 10])
          >> -(m_digit[qi::_val += qi::_1 ])
    );

//34,142,00:21:22.688405248,EURN,1,P,~,,,,,,~,P
qi::rule<std::string::iterator, uint64_t()>
m_wire_msg = ( qi::as_string[*qi::alpha] >> "," // symbol
                                         >> qi::ulong_ >> ","        // symbol seq num
                                         >> qi::char_ >> ","             // security_status
                                         >> qi::char_ >> ","             // halt_condition
                                         >> (m_fixed_point | qi::attr(0ul) )>> ","  //price1
                                         >> (m_fixed_point | qi::attr(0ul)) >> ","  //price2
                                         >> (qi::char_ | qi::attr('\0')) >> ","             // ssr trigger
                                         >> (qi::uint_ | qi::attr(0u))>> ","             // ssr trigger volume
                                         >> (qi::uint_ | qi::attr(0u))>> ","   // time
                                         >> qi::char_ >> ","             // ssr state
                                         >> qi::char_ )[qi::_val = 0];       

std::string s3 = "AAPL,1,P,~,,,,,,~,P";
ok = parse( s3.begin(), s3.end(), m_wire_msg );
std::cout << "ok3=" << ok << std::endl;

但是以某种方式失败了,我也不十分清楚为什么。

非常感谢您的帮助!

0 个答案:

没有答案