factor out file matching into own class
This commit is contained in:
parent
38986302e9
commit
a9f2879889
|
@ -116,6 +116,31 @@ std::string Settings::Suppressions::parseFile(std::istream &istr)
|
|||
return "";
|
||||
}
|
||||
|
||||
std::string Settings::Suppressions::FileMatcher::addFile(const std::string &name, unsigned int line)
|
||||
{
|
||||
_files[name].insert(line);
|
||||
return "";
|
||||
}
|
||||
|
||||
bool Settings::Suppressions::FileMatcher::isSuppressed(const std::string &file, unsigned int line)
|
||||
{
|
||||
// Check are all errors of this type filtered out
|
||||
if (_files.find("") != _files.end())
|
||||
return true;
|
||||
|
||||
if (_files.find(file) == _files.end())
|
||||
return false;
|
||||
|
||||
// Check should all errors in this file be filtered out
|
||||
if (std::find(_files[file].begin(), _files[file].end(), 0U) != _files[file].end())
|
||||
return true;
|
||||
|
||||
if (std::find(_files[file].begin(), _files[file].end(), line) == _files[file].end())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Settings::Suppressions::addSuppression(const std::string &errorId, const std::string &file, unsigned int line)
|
||||
{
|
||||
// Check that errorId is valid..
|
||||
|
@ -135,10 +160,7 @@ std::string Settings::Suppressions::addSuppression(const std::string &errorId, c
|
|||
}
|
||||
}
|
||||
|
||||
_suppressions[errorId][file].push_back(line);
|
||||
_suppressions[errorId][file].sort();
|
||||
|
||||
return "";
|
||||
return _suppressions[errorId].addFile(file, line);
|
||||
}
|
||||
|
||||
bool Settings::Suppressions::isSuppressed(const std::string &errorId, const std::string &file, unsigned int line)
|
||||
|
@ -146,21 +168,7 @@ bool Settings::Suppressions::isSuppressed(const std::string &errorId, const std:
|
|||
if (_suppressions.find(errorId) == _suppressions.end())
|
||||
return false;
|
||||
|
||||
// Check are all errors of this type filtered out
|
||||
if (_suppressions[errorId].find("") != _suppressions[errorId].end())
|
||||
return true;
|
||||
|
||||
if (_suppressions[errorId].find(file) == _suppressions[errorId].end())
|
||||
return false;
|
||||
|
||||
// Check should all errors in this file be filtered out
|
||||
if (std::find(_suppressions[errorId][file].begin(), _suppressions[errorId][file].end(), 0) != _suppressions[errorId][file].end())
|
||||
return true;
|
||||
|
||||
if (std::find(_suppressions[errorId][file].begin(), _suppressions[errorId][file].end(), line) == _suppressions[errorId][file].end())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return _suppressions[errorId].isSuppressed(file, line);
|
||||
}
|
||||
|
||||
std::string Settings::addEnabled(const std::string &str)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <string>
|
||||
#include <istream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
/// @addtogroup Core
|
||||
/// @{
|
||||
|
@ -135,8 +136,42 @@ public:
|
|||
class Suppressions
|
||||
{
|
||||
private:
|
||||
class FileMatcher
|
||||
{
|
||||
private:
|
||||
/** @brief List of filenames suppressed. */
|
||||
std::map<std::string, std::set<unsigned int> > _files;
|
||||
/** @brief List of globs suppressed. */
|
||||
std::map<std::string, std::set<unsigned int> > _globs;
|
||||
|
||||
/**
|
||||
* @brief Match a name against a glob pattern.
|
||||
* @param pattern The glob pattern to match.
|
||||
* @param name The filename to match against the glob pattern.
|
||||
* @return match success
|
||||
*/
|
||||
static bool match(const std::string &pattern, const std::string &name);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Add a file or glob (and line number).
|
||||
* @param name File name or glob pattern
|
||||
* @param line Line number
|
||||
* @return error message. empty upon success
|
||||
*/
|
||||
std::string addFile(const std::string &name, unsigned int line);
|
||||
|
||||
/**
|
||||
* @brief Returns true if the file name matches a previously added file or glob pattern.
|
||||
* @param name File name to check
|
||||
* @param line Line number
|
||||
* @return true if this filename/line matches
|
||||
*/
|
||||
bool isSuppressed(const std::string &file, unsigned int line);
|
||||
};
|
||||
|
||||
/** @brief List of error which the user doesn't want to see. */
|
||||
std::map<std::string, std::map<std::string, std::list<unsigned int> > > _suppressions;
|
||||
std::map<std::string, FileMatcher> _suppressions;
|
||||
public:
|
||||
/**
|
||||
* @brief Don't show errors listed in the file.
|
||||
|
|
Loading…
Reference in New Issue