parses an int/bool option from the command line
| 3463 | |
| 3464 | // parses an int/bool option from the command line |
| 3465 | bool parseIntOption(int argc, const char* const* argv, const char* pattern, optionType type, |
| 3466 | int& res) { |
| 3467 | String parsedValue; |
| 3468 | if(!parseOption(argc, argv, pattern, &parsedValue)) |
| 3469 | return false; |
| 3470 | |
| 3471 | if(type) { |
| 3472 | // integer |
| 3473 | // TODO: change this to use std::stoi or something else! currently it uses undefined behavior - assumes '0' on failed parse... |
| 3474 | int theInt = std::atoi(parsedValue.c_str()); |
| 3475 | if (theInt != 0) { |
| 3476 | res = theInt; //!OCLINT parameter reassignment |
| 3477 | return true; |
| 3478 | } |
| 3479 | } else { |
| 3480 | // boolean |
| 3481 | const char positive[][5] = { "1", "true", "on", "yes" }; // 5 - strlen("true") + 1 |
| 3482 | const char negative[][6] = { "0", "false", "off", "no" }; // 6 - strlen("false") + 1 |
| 3483 | |
| 3484 | // if the value matches any of the positive/negative possibilities |
| 3485 | for (unsigned i = 0; i < 4; i++) { |
| 3486 | if (parsedValue.compare(positive[i], true) == 0) { |
| 3487 | res = 1; //!OCLINT parameter reassignment |
| 3488 | return true; |
| 3489 | } |
| 3490 | if (parsedValue.compare(negative[i], true) == 0) { |
| 3491 | res = 0; //!OCLINT parameter reassignment |
| 3492 | return true; |
| 3493 | } |
| 3494 | } |
| 3495 | } |
| 3496 | return false; |
| 3497 | } |
| 3498 | } // namespace |
| 3499 | |
| 3500 | Context::Context(int argc, const char* const* argv) |
nothing calls this directly
no test coverage detected