How to parse a duration with spirit' qi

43 Views Asked by At

I want to parse something like "1m2s3ms" where each part is optional e.g. "1m3ms"

qi::int_parser<sint64, 10> dec64;
const qi::rule<const char *, sint64()> nsRule = dec64 >> qi::lit("ns");
const qi::rule<const char *, sint64()> usRule = dec64 >> qi::lit("us");
const qi::rule<const char *, sint64()> msRule = dec64 >> qi::lit("ms");
const qi::rule<const char *, sint64()> sRule = dec64 >> qi::lit("s");
const qi::rule<const char *, sint64()> mRule = dec64 >> qi::lit("m");
const qi::rule<const char *, sint64()> hRule = dec64 >> qi::lit("h");
auto result = qi::parse(f, f + length, 
  -hRule >>
  -mRule >>
  -sRule >>
  -msRule >>
  -usRule >>
  -nsRule, h, m, s, ms, us, ns);

The problem is, that the mRule and msRule are very similar and mRule wins while parsing the example above. Is there any directive I can use?

0

There are 0 best solutions below