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

Method parseEnabled

lib/settings.cpp:221–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219}
220
221std::string Settings::parseEnabled(const std::string &str, std::tuple<SimpleEnableGroup<Severity>, SimpleEnableGroup<Checks>> &groups)
222{
223 // Enable parameters may be comma separated...
224 if (str.find(',') != std::string::npos) {
225 std::string::size_type prevPos = 0;
226 std::string::size_type pos = 0;
227 while ((pos = str.find(',', pos)) != std::string::npos) {
228 if (pos == prevPos)
229 return std::string("--enable parameter is empty");
230 std::string errmsg(parseEnabled(str.substr(prevPos, pos - prevPos), groups));
231 if (!errmsg.empty())
232 return errmsg;
233 ++pos;
234 prevPos = pos;
235 }
236 if (prevPos >= str.length())
237 return std::string("--enable parameter is empty");
238 return parseEnabled(str.substr(prevPos), groups);
239 }
240
241 auto& severity = std::get<0>(groups);
242 auto& checks = std::get<1>(groups);
243
244 if (str == "all") {
245 // "error" is always enabled and cannot be controlled - so exclude it from "all"
246 SimpleEnableGroup<Severity> newSeverity;
247 newSeverity.fill();
248 newSeverity.disable(Severity::error);
249 severity.enable(newSeverity);
250 checks.enable(Checks::missingInclude);
251 checks.enable(Checks::unusedFunction);
252 } else if (str == "warning") {
253 severity.enable(Severity::warning);
254 } else if (str == "style") {
255 severity.enable(Severity::style);
256 } else if (str == "performance") {
257 severity.enable(Severity::performance);
258 } else if (str == "portability") {
259 severity.enable(Severity::portability);
260 } else if (str == "information") {
261 severity.enable(Severity::information);
262 } else if (str == "unusedFunction") {
263 checks.enable(Checks::unusedFunction);
264 } else if (str == "missingInclude") {
265 checks.enable(Checks::missingInclude);
266 }
267#ifdef CHECK_INTERNAL
268 else if (str == "internal") {
269 checks.enable(Checks::internalCheck);
270 }
271#endif
272 else {
273 // the actual option is prepending in the applyEnabled() call
274 if (str.empty())
275 return " parameter is empty";
276 return " parameter with the unknown name '" + str + "'";
277 }
278

Callers

nothing calls this directly

Calls 6

fillMethod · 0.80
disableMethod · 0.80
enableMethod · 0.80
ifFunction · 0.50
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected