Fixed diagram paths filtering
This commit is contained in:
@@ -329,13 +329,13 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
{
|
||||
// Process inclusive filters
|
||||
if (c.include) {
|
||||
inclusive_.emplace_back(std::make_unique<namespace_filter>(
|
||||
add_inclusive_filter(std::make_unique<namespace_filter>(
|
||||
filter_t::kInclusive, c.include().namespaces));
|
||||
inclusive_.emplace_back(std::make_unique<relationship_filter>(
|
||||
add_inclusive_filter(std::make_unique<relationship_filter>(
|
||||
filter_t::kInclusive, c.include().relationships));
|
||||
inclusive_.emplace_back(std::make_unique<access_filter>(
|
||||
add_inclusive_filter(std::make_unique<access_filter>(
|
||||
filter_t::kInclusive, c.include().access));
|
||||
inclusive_.emplace_back(std::make_unique<paths_filter>(
|
||||
add_inclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kInclusive, c.base_directory(), c.include().paths));
|
||||
|
||||
// Include any of these matches even if one them does not match
|
||||
@@ -347,26 +347,26 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
element_filters.emplace_back(std::make_unique<context_filter>(
|
||||
filter_t::kInclusive, c.include().context));
|
||||
|
||||
inclusive_.emplace_back(std::make_unique<anyof_filter>(
|
||||
add_inclusive_filter(std::make_unique<anyof_filter>(
|
||||
filter_t::kInclusive, std::move(element_filters)));
|
||||
}
|
||||
|
||||
// Process exclusive filters
|
||||
if (c.exclude) {
|
||||
exclusive_.emplace_back(std::make_unique<namespace_filter>(
|
||||
add_exclusive_filter(std::make_unique<namespace_filter>(
|
||||
filter_t::kExclusive, c.exclude().namespaces));
|
||||
exclusive_.emplace_back(std::make_unique<element_filter>(
|
||||
add_exclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kExclusive, c.base_directory(), c.exclude().paths));
|
||||
add_exclusive_filter(std::make_unique<element_filter>(
|
||||
filter_t::kExclusive, c.exclude().elements));
|
||||
exclusive_.emplace_back(std::make_unique<relationship_filter>(
|
||||
add_exclusive_filter(std::make_unique<relationship_filter>(
|
||||
filter_t::kExclusive, c.exclude().relationships));
|
||||
exclusive_.emplace_back(std::make_unique<access_filter>(
|
||||
add_exclusive_filter(std::make_unique<access_filter>(
|
||||
filter_t::kExclusive, c.exclude().access));
|
||||
exclusive_.emplace_back(std::make_unique<subclass_filter>(
|
||||
add_exclusive_filter(std::make_unique<subclass_filter>(
|
||||
filter_t::kExclusive, c.exclude().subclasses));
|
||||
exclusive_.emplace_back(std::make_unique<context_filter>(
|
||||
add_exclusive_filter(std::make_unique<context_filter>(
|
||||
filter_t::kExclusive, c.exclude().context));
|
||||
exclusive_.emplace_back(std::make_unique<paths_filter>(
|
||||
filter_t::kInclusive, c.base_directory(), c.exclude().paths));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,10 +90,12 @@ public:
|
||||
{
|
||||
std::filesystem::path res;
|
||||
|
||||
for (const auto &pe : path_) {
|
||||
res /= pe;
|
||||
for (const auto &path_element : path_) {
|
||||
res /= path_element;
|
||||
}
|
||||
|
||||
res /= name();
|
||||
|
||||
if (is_absolute_)
|
||||
res = "/" / res;
|
||||
else
|
||||
|
||||
@@ -202,32 +202,22 @@ template <>
|
||||
bool starts_with(
|
||||
const std::filesystem::path &path, const std::filesystem::path &prefix)
|
||||
{
|
||||
if (path == prefix)
|
||||
return true;
|
||||
auto normal_path = std::filesystem::path();
|
||||
auto normal_prefix = std::filesystem::path();
|
||||
|
||||
const int path_length = std::distance(std::begin(path), std::end(path));
|
||||
for (const auto &element : path.lexically_normal()) {
|
||||
if (!element.empty())
|
||||
normal_path /= element;
|
||||
}
|
||||
|
||||
auto last_nonempty_prefix_element = std::prev(std::find_if(
|
||||
prefix.begin(), prefix.end(), [](auto &&n) { return n.empty(); }));
|
||||
for (const auto &element : prefix.lexically_normal()) {
|
||||
if (!element.empty())
|
||||
normal_prefix /= element;
|
||||
}
|
||||
|
||||
int prefix_length =
|
||||
std::distance(std::begin(prefix), last_nonempty_prefix_element);
|
||||
|
||||
// Empty prefix always matches
|
||||
if (prefix_length == 0)
|
||||
return true;
|
||||
|
||||
// Prefix longer then path never matches
|
||||
if (prefix_length >= path_length)
|
||||
return false;
|
||||
|
||||
auto path_compare_end = path.begin();
|
||||
std::advance(path_compare_end, prefix_length);
|
||||
|
||||
std::vector<std::string> pref(prefix.begin(), last_nonempty_prefix_element);
|
||||
std::vector<std::string> pat(path.begin(), path_compare_end);
|
||||
|
||||
return pref == pat;
|
||||
return std::search(normal_path.begin(), normal_path.end(),
|
||||
normal_prefix.begin(),
|
||||
normal_prefix.end()) == normal_path.begin();
|
||||
}
|
||||
|
||||
template <> bool starts_with(const std::string &s, const std::string &prefix)
|
||||
|
||||
@@ -144,20 +144,20 @@ template <typename T> void append(std::vector<T> &l, const std::vector<T> &r)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if container starts with a prefix.
|
||||
* @brief Checks if collection starts with a prefix.
|
||||
*
|
||||
* @tparam T e.g. std::vector<std::string>
|
||||
* @param con Container to be checked against prefix
|
||||
* @param col Collection to be checked against prefix
|
||||
* @param prefix Container, which specifies the prefix
|
||||
* @return true if first prefix.size() elements of con are equal to prefix
|
||||
* @return true if first prefix.size() elements of col are equal to prefix
|
||||
*/
|
||||
template <typename T> bool starts_with(const T &con, const T &prefix)
|
||||
template <typename T> bool starts_with(const T &col, const T &prefix)
|
||||
{
|
||||
if (prefix.size() > con.size())
|
||||
if (prefix.size() > col.size())
|
||||
return false;
|
||||
|
||||
return T(prefix.begin(), prefix.end()) ==
|
||||
T(con.begin(), con.begin() + prefix.size());
|
||||
return std::search(col.begin(), col.end(), prefix.begin(), prefix.end()) ==
|
||||
col.begin();
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
Reference in New Issue
Block a user