Added initial support for include graph diagrams
This commit is contained in:
@@ -198,5 +198,37 @@ bool replace_all(
|
||||
return replaced;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool starts_with(
|
||||
const std::filesystem::path &path, const std::filesystem::path &prefix)
|
||||
{
|
||||
if(path == prefix)
|
||||
return true;
|
||||
|
||||
const int path_length = std::distance(std::begin(path), std::end(path));
|
||||
|
||||
auto last_nonempty_prefix_element = std::prev(std::find_if(
|
||||
prefix.begin(), prefix.end(), [](auto &&n) { return n.empty(); }));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@@ -143,23 +144,26 @@ template <typename T> void append(std::vector<T> &l, const std::vector<T> &r)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if vector starts with a prefix.
|
||||
* @brief Checks if container starts with a prefix.
|
||||
*
|
||||
* @tparam T
|
||||
* @param col
|
||||
* @param prefix
|
||||
* @return
|
||||
* @tparam T e.g. std::vector<std::string>
|
||||
* @param con Container 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
|
||||
*/
|
||||
template <typename T>
|
||||
bool starts_with(const std::vector<T> &col, const std::vector<T> &prefix)
|
||||
template <typename T> bool starts_with(const T &con, const T &prefix)
|
||||
{
|
||||
if (prefix.size() > col.size())
|
||||
if (prefix.size() > con.size())
|
||||
return false;
|
||||
|
||||
return std::vector<std::string>(prefix.begin(), prefix.end()) ==
|
||||
std::vector<std::string>(col.begin(), col.begin() + prefix.size());
|
||||
return T(prefix.begin(), prefix.end()) ==
|
||||
T(con.begin(), con.begin() + prefix.size());
|
||||
}
|
||||
|
||||
template <>
|
||||
bool starts_with(
|
||||
const std::filesystem::path &path, const std::filesystem::path &prefix);
|
||||
|
||||
template <typename T>
|
||||
bool ends_with(const std::vector<T> &col, const std::vector<T> &suffix)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user