Last active
May 2, 2016 23:02
-
-
Save eyalroz/011060ea931e1704d0dbc60cedc6d5b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void add_unrecognized_options(TestConfiguration& config, const std::vector<string>& unrecognized_options) | |
{ | |
// TODO: make sure all unrecognized options are of the form --option=value | |
// I'm sure the following can be made more elegant... | |
enum { OptionName, OptionValue } now_expecting = OptionName; | |
std::string option_name; | |
for(auto it = unrecognized_options.begin(); it != unrecognized_options.end(); it++) { | |
std::string option_value; | |
if (now_expecting == OptionValue) { | |
option_value = *it; | |
// Note! Not checking for '=' or ' ' characters in option values, if we know it's a value | |
if (option_value.find_first_not_of('-') == 2) { | |
// Got another option instead of a value, must be a flag option | |
// std::cout << "Inserting " << option_name << " as empty" << std::endl; | |
config.extra_options.insert(make_pair(option_name, std::string())); | |
option_name = option_value; | |
now_expecting = OptionValue; | |
continue; | |
} | |
} | |
else { | |
std::string s(*it); | |
auto key_starts = s.find_first_not_of('-'); | |
util::enforce(key_starts != string::npos, "Couldn't determine option name for " + s); | |
auto option_name_ends = s.find_first_of(" =\n", key_starts); | |
if (option_name_ends == string::npos) { | |
now_expecting = OptionValue; | |
option_name = s.substr(key_starts); | |
continue; | |
} | |
option_name = s.substr(key_starts, option_name_ends - key_starts); | |
auto value_starts = s.find_first_not_of(" =\n", option_name_ends + 1); | |
if (value_starts == string::npos) { | |
now_expecting = OptionValue; | |
continue; | |
} | |
// string value = s.substr(value_starts); | |
option_value = s.substr(value_starts); | |
} | |
config.extra_options.insert(make_pair(option_name, option_value)); | |
now_expecting = OptionName; | |
} | |
if (now_expecting != OptionName) { | |
config.extra_options.insert(make_pair(option_name, std::string())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment