I have a string to tokenize. It's form is HHmmssff
where H
, m
, s
, f
are digits.
It's supposed to be tokenized into four 2-digit numbers, but I need it to also accept short-hand forms, like sff
so it interprets it as 00000sff
.
I wanted to use boost::tokenizer
's offset_separator
but it seems to work only with positive offsets and I'd like to have it work sort of backwards.
Ok, one idea is to pad the string with zeroes from the left, but maybe the community comes up with something uber-smart. ;)
Edit: Additional requirements have just come into play.
The basic need for a smarter solution was to handle all cases, like f
, ssff
, mssff
, etc. but also accept a more complete time notation, like HH:mm:ss:ff
with its short-hand forms, e.g. s:ff
or even s:
(this one's supposed to be interpreted as s:00
).
In the case where the string ends with :
I can obviously pad it with two zeroes as well, then strip out all separators leaving just the digits and parse the resulting string with spirit.
But it seems like it would be a bit simpler if there was a way to make the offset tokenizer going back from the end of string (offsets -2, -4, -6, -8) and lexically cast the numbers to int
s.