MCPcopy Create free account
hub / github.com/Compaile/ctrack / parseIntOption

Function parseIntOption

test/doctest.h:6582–6614  ·  view source on GitHub ↗

parses an int/bool option from the command line

Source from the content-addressed store, hash-verified

6580
6581 // parses an int/bool option from the command line
6582 bool parseIntOption(int argc, const char* const* argv, const char* pattern, optionType type,
6583 int& res) {
6584 String parsedValue;
6585 if(!parseOption(argc, argv, pattern, &parsedValue))
6586 return false;
6587
6588 if(type) {
6589 // integer
6590 // TODO: change this to use std::stoi or something else! currently it uses undefined behavior - assumes '0' on failed parse...
6591 int theInt = std::atoi(parsedValue.c_str());
6592 if (theInt != 0) {
6593 res = theInt; //!OCLINT parameter reassignment
6594 return true;
6595 }
6596 } else {
6597 // boolean
6598 const char positive[][5] = { "1", "true", "on", "yes" }; // 5 - strlen("true") + 1
6599 const char negative[][6] = { "0", "false", "off", "no" }; // 6 - strlen("false") + 1
6600
6601 // if the value matches any of the positive/negative possibilities
6602 for (unsigned i = 0; i < 4; i++) {
6603 if (parsedValue.compare(positive[i], true) == 0) {
6604 res = 1; //!OCLINT parameter reassignment
6605 return true;
6606 }
6607 if (parsedValue.compare(negative[i], true) == 0) {
6608 res = 0; //!OCLINT parameter reassignment
6609 return true;
6610 }
6611 }
6612 }
6613 return false;
6614 }
6615} // namespace
6616
6617Context::Context(int argc, const char* const* argv)

Callers

nothing calls this directly

Calls 1

parseOptionFunction · 0.85

Tested by

no test coverage detected