4

I'm new to using Using boost::program_options, and I'd like to parse a numeric command line argument with colon and comma notation. For example i'd like to have this kind of argument:

myprogram --numbers 1:100,200,300

Produce a vector with the integers 1-100 then 200 and finally 300.

Is there a name for this notation?

My first inclination is that I'd have to treat this argument as a string, then pass it to a function function that does the parsing. It seems like this is an excellent candidate for "somthing someone has done already and made available."

2NinerRomeo
  • 2,687
  • 4
  • 29
  • 35
  • possible duplicate of [Does C# have built-in support for parsing page-number strings?](http://stackoverflow.com/questions/40161/does-c-sharp-have-built-in-support-for-parsing-page-number-strings) – Phil H Oct 01 '12 at 12:55
  • Sounds like a great job for regex – Scott Jones Apr 27 '13 at 21:04

1 Answers1

0

I would use boost::spirit and define some custom semantic actions. Make sure the version of boost::spirit you use is compatible with the compiler with this. I've had issues with using newer boost::spirit with older compilers. Matlab calls the 1:5 "colon notation". Pretty anti-climactic eh?