Reputation: 7539
I would like to use boost::program_options to read the options from a configuration file, allowing for a case insensitive parsing.
Consider, e.g., the following simple code:
#include <iostream>
#include <fstream>
#include <string>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
int main()
{
using namespace std;
namespace po = boost::program_options;
ifstream inputfile("input.dat");
po::options_description desc("");
desc.add_options()
("l", po::value<unsigned int>())
;
po::variables_map vm;
po::store(po::parse_config_file(inputfile, desc), vm);
po::notify(vm);
if (vm.count("l"))
cout << "l is set as " << vm["l"].as<unsigned int>() << endl;
else
cout << "l is not set";
return 0;
}
With the following input.dat
file
l=3
the program runs fine giving output
l is set as 3
If I change the input.dat
as
L=3
the program terminates raising an exception
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::unknown_option> >'
what(): unrecognised option 'L'
Aborted
Case-insensitive parsing is apparently possible on the command-line, see the discussion here. Is it possible to have a case-insentive parsing also for reading from a configuration file?
Upvotes: 2
Views: 277
Reputation: 393114
That's not an option.
You can suggest features to the library maintainers.
You can eithr convert the inifile to preferred case using other tools, or add options descriptions for case complements.
Upvotes: 1