From 0abc6296b31eeb8458ac1eed5a87d9ba43dcf6b9 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Fri, 26 Feb 2021 21:39:55 +0100 Subject: [PATCH] Fixed nested class namespace rendering --- src/util/util.h | 26 +++++++++++++++++++++++++- tests/t00004/.clanguml | 2 ++ tests/test_cases.cc | 6 +++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/util/util.h b/src/util/util.h index 7bccd04e..148459d9 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -23,6 +23,30 @@ namespace clanguml { namespace util { +std::vector split(std::string str, std::string delimiter) +{ + std::vector result; + + while (str.size()) { + int index = str.find(delimiter); + if (index != std::string::npos) { + result.push_back(str.substr(0, index)); + str = str.substr(index + delimiter.size()); + if (str.size() == 0) + result.push_back(str); + } + else { + result.push_back(str); + str = ""; + } + } + + if (result.empty()) + result.push_back(str); + + return result; +} + std::string namespace_relative( const std::vector &namespaces, const std::string &n) { @@ -31,7 +55,7 @@ std::string namespace_relative( continue; if (n == ns) - return ""; + return split(n, "::").back(); if (n.find(ns) == 0) { if (n.size() <= ns.size() + 2) diff --git a/tests/t00004/.clanguml b/tests/t00004/.clanguml index 81badcaf..57824ca7 100644 --- a/tests/t00004/.clanguml +++ b/tests/t00004/.clanguml @@ -6,6 +6,8 @@ diagrams: glob: - ../../tests/t00004/t00004.cc using_namespace: + - clanguml::t00004::A::AA + - clanguml::t00004::A - clanguml::t00004 include: namespaces: diff --git a/tests/test_cases.cc b/tests/test_cases.cc index 715bf63d..066cd4ff 100644 --- a/tests/test_cases.cc +++ b/tests/test_cases.cc @@ -255,9 +255,9 @@ TEST_CASE("Test t00004", "[unit-test]") REQUIRE_THAT(puml, StartsWith("@startuml")); REQUIRE_THAT(puml, EndsWith("@enduml\n")); REQUIRE_THAT(puml, Contains("class A")); - REQUIRE_THAT(puml, Contains("A +-- A::AA")); - REQUIRE_THAT(puml, Contains("A::AA +-- A::AA::AAA")); - REQUIRE_THAT(puml, Contains("A::AA +-- A::AA::Lights")); + REQUIRE_THAT(puml, Contains("A +-- AA")); + REQUIRE_THAT(puml, Contains("AA +-- AAA")); + REQUIRE_THAT(puml, Contains("AA +-- Lights")); save_puml( "./" + config.output_directory + "/" + diagram->name + ".puml", puml);