MCPcopy Create free account
hub / github.com/Tablecruncher/tablecruncher / parseOptionImpl

Function parseOptionImpl

external/utf8-cpp-utils/test/doctest.h:6450–6482  ·  view source on GitHub ↗

the implementation of parseOption()

Source from the content-addressed store, hash-verified

6448
6449 // the implementation of parseOption()
6450 bool parseOptionImpl(int argc, const char* const* argv, const char* pattern, String* value) {
6451 // going from the end to the beginning and stopping on the first occurrence from the end
6452 for(int i = argc; i > 0; --i) {
6453 auto index = i - 1;
6454 auto temp = std::strstr(argv[index], pattern);
6455 if(temp && (value || strlen(temp) == strlen(pattern))) { //!OCLINT prefer early exits and continue
6456 // eliminate matches in which the chars before the option are not '-'
6457 bool noBadCharsFound = true;
6458 auto curr = argv[index];
6459 while(curr != temp) {
6460 if(*curr++ != '-') {
6461 noBadCharsFound = false;
6462 break;
6463 }
6464 }
6465 if(noBadCharsFound && argv[index][0] == '-') {
6466 if(value) {
6467 // parsing the value of an option
6468 temp += strlen(pattern);
6469 const unsigned len = strlen(temp);
6470 if(len) {
6471 *value = temp;
6472 return true;
6473 }
6474 } else {
6475 // just a flag - no value
6476 return true;
6477 }
6478 }
6479 }
6480 }
6481 return false;
6482 }
6483
6484 // parses an option and returns the string after the '=' character
6485 bool parseOption(int argc, const char* const* argv, const char* pattern, String* value = nullptr,

Callers 1

parseOptionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected