argv[i] for i = offset..argc-1 are overwriting options
| 219 | |
| 220 | // argv[i] for i = offset..argc-1 are overwriting options |
| 221 | std::vector<std::pair<std::string, std::string>> Options::get_command_line_options(int argc, char* argv[], size_t offset) { |
| 222 | static const std::string delimiter = "="; |
| 223 | std::vector<std::pair<std::string, std::string>> command_line_options; |
| 224 | |
| 225 | // build the (name, value) map |
| 226 | for (size_t i = offset; i < static_cast<size_t>(argc); ++i) { |
| 227 | const std::string argument = std::string(argv[i]); |
| 228 | size_t position = argument.find_first_of(delimiter); |
| 229 | if (position == std::string::npos) { |
| 230 | throw std::runtime_error("The option " + argument + " does not contain the delimiter " + delimiter); |
| 231 | } |
| 232 | const std::string option_name = argument.substr(0, position); |
| 233 | const std::string option_value = argument.substr(position + 1); |
| 234 | command_line_options.emplace_back(option_name, option_value); |
| 235 | } |
| 236 | return command_line_options; |
| 237 | } |
| 238 | |
| 239 | void trim(std::string& string) { |
| 240 | string.erase(0, string.find_first_not_of(" \n\r\t")); |
nothing calls this directly
no test coverage detected