| 31 | typedef std::pair<bool, ArgsIt> AfterOpt; |
| 32 | |
| 33 | AfterOpt get_option(Args& args, const std::string& opt) |
| 34 | { |
| 35 | for (ArgsIt args_it = args.begin(); args_it != args.end(); ++args_it) { |
| 36 | if (*args_it == "--") { |
| 37 | // Remaining arguments should be interpreted as positional arguments |
| 38 | return AfterOpt(false, args.end()); |
| 39 | } |
| 40 | if (opt.length() <= args_it->length()) { |
| 41 | const bool starts_with = args_it->substr(0, opt.length()) == opt; |
| 42 | const bool same_size = args_it->length() == opt.length(); |
| 43 | if (starts_with && !same_size && args_it->at(opt.length()) == '=') { |
| 44 | // Form is OPT=VALUE, replace current with VALUE |
| 45 | *args_it = args_it->substr(opt.length() + 1); |
| 46 | return AfterOpt(true, args_it); |
| 47 | } else if (same_size && starts_with) { |
| 48 | // Form is OPT VALUE?, return next argument |
| 49 | return AfterOpt(true, args.erase(args_it)); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | return AfterOpt(false, args.end()); |
| 54 | } |
| 55 | |
| 56 | bool has_option(Args& args, const std::string& opt) |
| 57 | { |
no test coverage detected