From 1a606a57fd0deeb768fe5fa87f44b33a49a8e898 Mon Sep 17 00:00:00 2001 From: Greg Hewgill Date: Sun, 20 Feb 2011 23:56:52 +1300 Subject: [PATCH] slightly more flexible detection of 'fall through' comment --- lib/preprocessor.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index c9d125d83..2e8cd86c5 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -303,6 +303,18 @@ static bool hasbom(const std::string &str) } +static bool isFallThroughComment(std::string comment) +{ + // convert comment to lower case without whitespace + std::transform(comment.begin(), comment.end(), comment.begin(), ::tolower); + comment.erase(std::remove_if(comment.begin(), comment.end(), ::isspace), comment.end()); + + return comment.find("fallthr") != std::string::npos || + comment.find("dropthr") != std::string::npos || + comment.find("passthr") != std::string::npos || + comment.find("nobreak") != std::string::npos; +} + std::string Preprocessor::removeComments(const std::string &str, const std::string &filename, Settings *settings) { // For the error report @@ -392,8 +404,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri } } - std::transform(comment.begin(), comment.end(), comment.begin(), ::tolower); - if (comment.find("fall") != std::string::npos && comment.find("thr") != std::string::npos) + if (isFallThroughComment(comment)) { suppressionIDs.push_back("switchCaseFallThrough"); } @@ -420,8 +431,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri } std::string comment(str, commentStart, i - commentStart); - std::transform(comment.begin(), comment.end(), comment.begin(), ::tolower); - if (comment.find("fall") != std::string::npos && comment.find("thr") != std::string::npos) + if (isFallThroughComment(comment)) { suppressionIDs.push_back("switchCaseFallThrough"); }