MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / parseNumberArg

Method parseNumberArg

cli/cmdlineparser.h:115–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113
114 template<typename T>
115 bool parseNumberArg(const char* const arg, std::size_t offset, T& num, bool mustBePositive = false)
116 {
117 T tmp;
118 std::string err;
119 if (!strToInt(arg + offset, tmp, &err)) {
120 mLogger.printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + ".");
121 return false;
122 }
123 if (mustBePositive && tmp < 0) {
124 mLogger.printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer.");
125 return false;
126 }
127 num = tmp;
128 return true;
129 }
130
131 /**
132 * Tries to load a library and prints warning/error messages

Callers

nothing calls this directly

Calls 2

strToIntFunction · 0.85
printErrorMethod · 0.45

Tested by

no test coverage detected