diff --git a/lib/settings.cpp b/lib/settings.cpp index 4b6f26c84..b99a06c32 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -70,46 +70,7 @@ std::string Settings::Suppressions::parseFile(std::istream &istr) if (line.length() >= 2 && line[0] == '/' && line[1] == '/') continue; - std::istringstream lineStream(line); - std::string id; - std::string file; - unsigned int lineNumber = 0; - if (std::getline(lineStream, id, ':')) - { - if (std::getline(lineStream, file)) - { - // If there is not a dot after the last colon in "file" then - // the colon is a separator and the contents after the colon - // is a line number.. - - // Get position of last colon - const std::string::size_type pos = file.rfind(":"); - - // if a colon is found and there is no dot after it.. - if (pos != std::string::npos && - file.find(".", pos) == std::string::npos) - { - // Try to parse out the line number - try - { - std::istringstream istr1(file.substr(pos+1)); - istr1 >> lineNumber; - } - catch (...) - { - lineNumber = 0; - } - - if (lineNumber > 0) - { - file.erase(pos); - } - } - } - } - - // We could perhaps check if the id is valid and return error if it is not - const std::string errmsg(addSuppression(id, file, lineNumber)); + const std::string errmsg(addSuppressionLine(line)); if (!errmsg.empty()) return errmsg; } @@ -117,6 +78,54 @@ std::string Settings::Suppressions::parseFile(std::istream &istr) return ""; } +std::string Settings::Suppressions::addSuppressionLine(const std::string &line) +{ + std::istringstream lineStream(line); + std::string id; + std::string file; + unsigned int lineNumber = 0; + if (std::getline(lineStream, id, ':')) + { + if (std::getline(lineStream, file)) + { + // If there is not a dot after the last colon in "file" then + // the colon is a separator and the contents after the colon + // is a line number.. + + // Get position of last colon + const std::string::size_type pos = file.rfind(":"); + + // if a colon is found and there is no dot after it.. + if (pos != std::string::npos && + file.find(".", pos) == std::string::npos) + { + // Try to parse out the line number + try + { + std::istringstream istr1(file.substr(pos+1)); + istr1 >> lineNumber; + } + catch (...) + { + lineNumber = 0; + } + + if (lineNumber > 0) + { + file.erase(pos); + } + } + } + } + + // We could perhaps check if the id is valid and return error if it is not + const std::string errmsg(addSuppression(id, file, lineNumber)); + if (!errmsg.empty()) + return errmsg; + + return ""; +} + bool Settings::Suppressions::FileMatcher::match(const std::string &pattern, const std::string &name) { const char *p = pattern.c_str(); diff --git a/lib/settings.h b/lib/settings.h index d2d9a217d..f480b3bec 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -180,6 +180,13 @@ public: */ std::string parseFile(std::istream &istr); + /** + * @brief Don't show the given error. + * @param str Description of error to suppress (in id:file:line format). + * @return error message. empty upon success + */ + std::string addSuppressionLine(const std::string &line); + /** * @brief Don't show this error. If file and/or line are optional. In which case * the errorId alone is used for filtering.