support capitalized option names in extract/prepare

This commit is contained in:
Emil Tin
2013-09-24 21:50:20 +02:00
parent 644fad8355
commit 5f90ed8b3e
5 changed files with 29 additions and 22 deletions
+11
View File
@@ -29,6 +29,7 @@ Custom validators for use with boost::program_options.
#include <boost/any.hpp>
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/regex.hpp>
#include <string>
#include <vector>
@@ -57,4 +58,14 @@ namespace boost {
}
}
//support old capitalized option names by downcasing them with a regex replace
//read from file and store in a stringstream that can be passed to boost::program_options
inline void PrepareConfigFile(const boost::filesystem::path& path, std::string& output ) {
std::ifstream config_stream(path.c_str());
std::string input_str( (std::istreambuf_iterator<char>(config_stream)), std::istreambuf_iterator<char>() );
boost::regex regex( "^([^=]*)" ); //match from start of line to '='
std::string format( "\\L$1\\E" ); //replace with downcased substring
output = boost::regex_replace( input_str, regex, format );
}
#endif /* PROGRAM_OPTIONS_H */