helper method to handle the arguments and put them nicely in arguments can be switched to ts::errata
| 381 | // helper method to handle the arguments and put them nicely in arguments |
| 382 | // can be switched to ts::errata |
| 383 | static std::string |
| 384 | handle_args(Arguments &ret, AP_StrVec &args, std::string const &name, unsigned arg_num, unsigned &index) |
| 385 | { |
| 386 | ArgumentData data; |
| 387 | ret.append(name, data); |
| 388 | // handle the args |
| 389 | if (arg_num == MORE_THAN_ZERO_ARG_N || arg_num == MORE_THAN_ONE_ARG_N) { |
| 390 | // infinite arguments |
| 391 | if (arg_num == MORE_THAN_ONE_ARG_N && args.size() <= index + 1) { |
| 392 | return "at least one argument expected by " + name; |
| 393 | } |
| 394 | for (unsigned j = index + 1; j < args.size(); j++) { |
| 395 | ret.append_arg(name, args[j]); |
| 396 | } |
| 397 | args.erase(args.begin() + index, args.end()); |
| 398 | return ""; |
| 399 | } |
| 400 | // finite number of argument handling |
| 401 | for (unsigned j = 0; j < arg_num; j++) { |
| 402 | if (args.size() < index + j + 2 || args[index + j + 1].empty()) { |
| 403 | return std::to_string(arg_num) + " argument(s) expected by " + name; |
| 404 | } |
| 405 | ret.append_arg(name, args[index + j + 1]); |
| 406 | } |
| 407 | // erase the used arguments and append the data to the return structure |
| 408 | args.erase(args.begin() + index, args.begin() + index + arg_num + 1); |
| 409 | index -= 1; |
| 410 | return ""; |
| 411 | } |
| 412 | |
| 413 | // Append the args of option to parsed data. Return true if there is any option called |
| 414 | void |