Here’s my less than robust solution that converts a line of input into a config file syntax, which I pass into stringstream.
char dashes[] = "--";
char dash[] = " -";
string::size_type loc;
string buffer;
// open file
ifstream ifp(s);
while (!ifp.eof() && ifp.good()) {
// read a line of input
getline(ifp, buffer);
// replace all occurrences of double-dash with newline
loc = buffer.rfind(dashes);
while (string::npos != loc) {
buffer[loc] = '\n';
buffer[loc+integer::one] = ' ';
loc = buffer.rfind(dashes);
}
// replace all occurrences of space-dash with newline
loc = buffer.rfind(dash);
while (string::npos != loc) {
buffer[loc+integer::one] = '\n';
loc = buffer.rfind(dash);
}
// check if first option has single dash without leading space
if ('-' == buffer[0]) {
// remove leading dash
buffer.erase(integer::zero, integer::one);
}
stringstream ss(buffer);
po::parse_config_file(ss, desc);
}
This still requires modifying our input files to use assignment form so this: