| 350 | } |
| 351 | |
| 352 | bool SuppressionList::Suppression::parseComment(std::string comment, std::string *errorMessage) |
| 353 | { |
| 354 | if (comment.size() < 2) |
| 355 | return false; |
| 356 | |
| 357 | if (comment.compare(comment.size() - 2, 2, "*/") == 0) |
| 358 | comment.erase(comment.size() - 2, 2); |
| 359 | |
| 360 | std::string::size_type extraPos = comment.find(';'); |
| 361 | std::string::size_type extraDelimiterSize = 1; |
| 362 | |
| 363 | if (extraPos == std::string::npos) { |
| 364 | extraPos = comment.find("//", 2); |
| 365 | extraDelimiterSize = 2; |
| 366 | } |
| 367 | |
| 368 | if (extraPos != std::string::npos) { |
| 369 | extraComment = trim(comment.substr(extraPos + extraDelimiterSize)); |
| 370 | for (auto it = extraComment.begin(); it != extraComment.end();) |
| 371 | it = *it & 0x80 ? extraComment.erase(it) : it + 1; |
| 372 | comment.erase(extraPos); |
| 373 | } |
| 374 | |
| 375 | const std::set<std::string> cppchecksuppress{ |
| 376 | "cppcheck-suppress", |
| 377 | "cppcheck-suppress-begin", |
| 378 | "cppcheck-suppress-end", |
| 379 | "cppcheck-suppress-file", |
| 380 | "cppcheck-suppress-macro" |
| 381 | }; |
| 382 | |
| 383 | std::istringstream iss(comment.substr(2)); |
| 384 | std::string word; |
| 385 | iss >> word; |
| 386 | if (!cppchecksuppress.count(word)) |
| 387 | return false; |
| 388 | |
| 389 | iss >> errorId; |
| 390 | if (!iss) |
| 391 | return false; |
| 392 | |
| 393 | const std::string symbolNameString = "symbolName="; |
| 394 | |
| 395 | while (iss) { |
| 396 | iss >> word; |
| 397 | if (!iss) |
| 398 | break; |
| 399 | if (word.find_first_not_of("+-*/%#;") == std::string::npos) |
| 400 | break; |
| 401 | if (startsWith(word, symbolNameString)) |
| 402 | symbolName = word.substr(symbolNameString.size()); |
| 403 | else if (errorMessage && errorMessage->empty()) |
| 404 | *errorMessage = "Bad suppression attribute '" + word + "'. You can write comments in the comment after a ; or //. Valid suppression attributes; symbolName=sym"; |
| 405 | } |
| 406 | return true; |
| 407 | } |
| 408 | |
| 409 | SuppressionList::Suppression::Result SuppressionList::Suppression::isSuppressed(const SuppressionList::ErrorMessage &errmsg) const |