the implementation of parseOption()
| 3358 | |
| 3359 | // the implementation of parseOption() |
| 3360 | bool parseOptionImpl(int argc, const char* const* argv, const char* pattern, String* value) { |
| 3361 | // going from the end to the beginning and stopping on the first occurrence from the end |
| 3362 | for(int i = argc; i > 0; --i) { |
| 3363 | auto index = i - 1; |
| 3364 | auto temp = std::strstr(argv[index], pattern); |
| 3365 | if(temp && (value || strlen(temp) == strlen(pattern))) { //!OCLINT prefer early exits and continue |
| 3366 | // eliminate matches in which the chars before the option are not '-' |
| 3367 | bool noBadCharsFound = true; |
| 3368 | auto curr = argv[index]; |
| 3369 | while(curr != temp) { |
| 3370 | if(*curr++ != '-') { |
| 3371 | noBadCharsFound = false; |
| 3372 | break; |
| 3373 | } |
| 3374 | } |
| 3375 | if(noBadCharsFound && argv[index][0] == '-') { |
| 3376 | if(value) { |
| 3377 | // parsing the value of an option |
| 3378 | temp += strlen(pattern); |
| 3379 | const unsigned len = strlen(temp); |
| 3380 | if(len) { |
| 3381 | *value = temp; |
| 3382 | return true; |
| 3383 | } |
| 3384 | } else { |
| 3385 | // just a flag - no value |
| 3386 | return true; |
| 3387 | } |
| 3388 | } |
| 3389 | } |
| 3390 | } |
| 3391 | return false; |
| 3392 | } |
| 3393 | |
| 3394 | // parses an option and returns the string after the '=' character |
| 3395 | bool parseOption(int argc, const char* const* argv, const char* pattern, String* value = nullptr, |