the implementation of parseOption()
| 6475 | |
| 6476 | // the implementation of parseOption() |
| 6477 | bool parseOptionImpl(int argc, const char* const* argv, const char* pattern, String* value) { |
| 6478 | // going from the end to the beginning and stopping on the first occurrence from the end |
| 6479 | for(int i = argc; i > 0; --i) { |
| 6480 | auto index = i - 1; |
| 6481 | auto temp = std::strstr(argv[index], pattern); |
| 6482 | if(temp && (value || strlen(temp) == strlen(pattern))) { //!OCLINT prefer early exits and continue |
| 6483 | // eliminate matches in which the chars before the option are not '-' |
| 6484 | bool noBadCharsFound = true; |
| 6485 | auto curr = argv[index]; |
| 6486 | while(curr != temp) { |
| 6487 | if(*curr++ != '-') { |
| 6488 | noBadCharsFound = false; |
| 6489 | break; |
| 6490 | } |
| 6491 | } |
| 6492 | if(noBadCharsFound && argv[index][0] == '-') { |
| 6493 | if(value) { |
| 6494 | // parsing the value of an option |
| 6495 | temp += strlen(pattern); |
| 6496 | const unsigned len = strlen(temp); |
| 6497 | if(len) { |
| 6498 | *value = temp; |
| 6499 | return true; |
| 6500 | } |
| 6501 | } else { |
| 6502 | // just a flag - no value |
| 6503 | return true; |
| 6504 | } |
| 6505 | } |
| 6506 | } |
| 6507 | } |
| 6508 | return false; |
| 6509 | } |
| 6510 | |
| 6511 | // parses an option and returns the string after the '=' character |
| 6512 | bool parseOption(int argc, const char* const* argv, const char* pattern, String* value = nullptr, |