Added regex support to namespaces filter
This commit is contained in:
@@ -48,7 +48,7 @@ struct regex {
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] bool operator==(const std::string &v)
|
||||
[[nodiscard]] bool operator==(const std::string &v) const
|
||||
{
|
||||
return std::regex_match(v, regexp);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ using string_or_regex = or_regex<std::string>;
|
||||
|
||||
std::string to_string(string_or_regex sr);
|
||||
|
||||
using namespace_or_regex = std::variant<common::model::namespace_, regex>;
|
||||
using namespace_or_regex = or_regex<common::model::namespace_>;
|
||||
|
||||
enum class method_arguments { full, abbreviated, none };
|
||||
|
||||
@@ -148,7 +148,7 @@ struct diagram_template {
|
||||
};
|
||||
|
||||
struct filter {
|
||||
std::vector<common::model::namespace_> namespaces;
|
||||
std::vector<namespace_or_regex> namespaces;
|
||||
|
||||
std::vector<string_or_regex> elements;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ using clanguml::config::location_t;
|
||||
using clanguml::config::member_order_t;
|
||||
using clanguml::config::method_arguments;
|
||||
using clanguml::config::method_type;
|
||||
using clanguml::config::namespace_or_regex;
|
||||
using clanguml::config::package_diagram;
|
||||
using clanguml::config::package_type_t;
|
||||
using clanguml::config::plantuml;
|
||||
@@ -360,6 +361,23 @@ template <> struct convert<string_or_regex> {
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct convert<namespace_or_regex> {
|
||||
static bool decode(const Node &node, namespace_or_regex &rhs)
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
if (node.IsMap()) {
|
||||
auto pattern = node["r"].as<std::string>();
|
||||
auto rx = std::regex(pattern);
|
||||
rhs = namespace_or_regex{std::move(rx), std::move(pattern)};
|
||||
}
|
||||
else {
|
||||
rhs = namespace_or_regex{node.as<std::string>()};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// filter Yaml decoder
|
||||
//
|
||||
@@ -368,7 +386,7 @@ template <> struct convert<filter> {
|
||||
{
|
||||
if (node["namespaces"]) {
|
||||
auto namespace_list =
|
||||
node["namespaces"].as<std::vector<std::string>>();
|
||||
node["namespaces"].as<decltype(rhs.namespaces)>();
|
||||
for (const auto &ns : namespace_list)
|
||||
rhs.namespaces.push_back({ns});
|
||||
}
|
||||
|
||||
@@ -65,6 +65,19 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const string_or_regex &m)
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const namespace_or_regex &m)
|
||||
{
|
||||
if (std::holds_alternative<common::model::namespace_>(m.value())) {
|
||||
out << std::get<common::model::namespace_>(m.value());
|
||||
}
|
||||
else {
|
||||
out << YAML::Key << "r" << YAML::Value
|
||||
<< std::get<regex>(m.value()).pattern;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const filter &f)
|
||||
{
|
||||
out << YAML::BeginMap;
|
||||
|
||||
Reference in New Issue
Block a user