Changed decorator tag from clanguml to uml

This commit is contained in:
Bartek Kryza
2021-07-30 13:14:30 +02:00
parent 7b9fe2ee2d
commit 0168edeba2
4 changed files with 75 additions and 25 deletions

View File

@@ -151,19 +151,21 @@ std::shared_ptr<decorator> aggregation::from_string(std::string_view c)
return res; return res;
} }
std::vector<std::shared_ptr<decorator>> parse(std::string documentation_block) std::vector<std::shared_ptr<decorator>> parse(
std::string documentation_block, std::string clanguml_tag)
{ {
std::vector<std::shared_ptr<decorator>> res; std::vector<std::shared_ptr<decorator>> res;
const std::string begin_tag{"@clanguml"}; const std::string begin_tag{"@" + clanguml_tag};
const auto begin_tag_size = begin_tag.size(); const auto begin_tag_size = begin_tag.size();
// First replace all \clanguml occurences with @clanguml // First replace all \uml occurences with @uml
util::replace_all(documentation_block, "\\clanguml", "@clanguml"); util::replace_all(
documentation_block, "\\" + clanguml_tag, "@" + clanguml_tag);
documentation_block = util::trim(documentation_block); documentation_block = util::trim(documentation_block);
std::string_view block_view{documentation_block}; std::string_view block_view{documentation_block};
auto pos = block_view.find("@clanguml{"); auto pos = block_view.find("@" + clanguml_tag + "{");
while (pos < documentation_block.size()) { while (pos < documentation_block.size()) {
auto c_begin = pos + begin_tag_size; auto c_begin = pos + begin_tag_size;
auto c_end = documentation_block.find("}", c_begin); auto c_end = documentation_block.find("}", c_begin);
@@ -177,7 +179,7 @@ std::vector<std::shared_ptr<decorator>> parse(std::string documentation_block)
if (com) if (com)
res.emplace_back(std::move(com)); res.emplace_back(std::move(com));
pos = block_view.find("@clanguml{", c_end); pos = block_view.find("@" + clanguml_tag + "{", c_end);
} }
return res; return res;

View File

@@ -24,7 +24,6 @@
namespace clanguml { namespace clanguml {
namespace decorators { namespace decorators {
// \clanguml{label:diagram1,diagram2[param] text}
struct decorator_toks { struct decorator_toks {
std::string label; std::string label;
std::vector<std::string> diagrams; std::vector<std::string> diagrams;
@@ -80,7 +79,8 @@ struct aggregation : public decorator {
static std::shared_ptr<decorator> from_string(std::string_view c); static std::shared_ptr<decorator> from_string(std::string_view c);
}; };
std::vector<std::shared_ptr<decorator>> parse(std::string documentation_block); std::vector<std::shared_ptr<decorator>> parse(
std::string documentation_block, std::string clanguml_tag = "uml");
} // namespace decorators } // namespace decorators
} // namespace clanguml } // namespace clanguml

View File

@@ -4,40 +4,40 @@
namespace clanguml { namespace clanguml {
namespace t00028 { namespace t00028 {
/// \clanguml{note[top] A class note.} /// \uml{note[top] A class note.}
class A { class A {
}; };
/// \clanguml{note[] B class note.} /// \uml{note[] B class note.}
class B { class B {
}; };
/// ///
/// @clanguml{note:t00028_class[bottom] C class note.} /// @uml{note:t00028_class[bottom] C class note.}
/// This is class C. /// This is class C.
class C { class C {
}; };
/// \clanguml{note /// \uml{note
/// D /// D
/// class /// class
/// note.} /// note.}
class D { class D {
}; };
/// \clanguml{note E template class note.} /// \uml{note E template class note.}
template <typename T> class E { template <typename T> class E {
T param; T param;
}; };
/// \clanguml{note:other_diagram[left] G class note.} /// \uml{note:other_diagram[left] G class note.}
class G { class G {
}; };
/// @clanguml{note[ bottom ] F enum note.} /// @uml{note[ bottom ] F enum note.}
enum class F { one, two, three }; enum class F { one, two, three };
/// \clanguml{note[right] R class note.} /// \uml{note[right] R class note.}
class R { class R {
A aaa; A aaa;

View File

@@ -52,12 +52,12 @@ TEST_CASE("Test decorator parser on note", "[unit-test]")
\param a int an int \param a int an int
\param b float a float \param b float a float
\clanguml{note[left] This is a comment} \uml{note[left] This is a comment}
@clanguml{note[ top ] @uml{note[ top ]
This is a comment } This is a comment }
\clanguml{note This is a comment} \uml{note This is a comment}
\clanguml{note[] This is a comment} \uml{note[] This is a comment}
)"; )";
using namespace clanguml::decorators; using namespace clanguml::decorators;
@@ -88,10 +88,58 @@ TEST_CASE("Test decorator parser on note", "[unit-test]")
CHECK(n4->text == "This is a comment"); CHECK(n4->text == "This is a comment");
} }
TEST_CASE("Test decorator parser on note with custom tag", "[unit-test]")
{
std::string comment = R"(
\brief This is a comment.
This is a longer comment.
\
\param a int an int
\param b float a float
\clanguml{note[left] This is a comment}
@clanguml{note[ top ]
This is a comment }
\clanguml{note This is a comment}
\clanguml{note[] This is a comment}
)";
using namespace clanguml::decorators;
auto decorators = parse(comment, "clanguml");
CHECK(decorators.size() == 4);
auto n1 = std::dynamic_pointer_cast<note>(decorators.at(0));
auto n2 = std::dynamic_pointer_cast<note>(decorators.at(1));
auto n3 = std::dynamic_pointer_cast<note>(decorators.at(2));
auto n4 = std::dynamic_pointer_cast<note>(decorators.at(3));
CHECK(n1);
CHECK(n1->position == "left");
CHECK(n1->text == "This is a comment");
CHECK(n2);
CHECK(n2->position == "top");
CHECK(n2->text == "This is a comment");
CHECK(n3);
CHECK(n3->position == "left");
CHECK(n3->text == "This is a comment");
CHECK(n4);
CHECK(n4->position == "left");
CHECK(n4->text == "This is a comment");
}
TEST_CASE("Test decorator parser on style", "[unit-test]") TEST_CASE("Test decorator parser on style", "[unit-test]")
{ {
std::string comment = R"( std::string comment = R"(
\clanguml{style[#green,dashed,thickness=4]} \uml{style[#green,dashed,thickness=4]}
)"; )";
using namespace clanguml::decorators; using namespace clanguml::decorators;
@@ -109,7 +157,7 @@ TEST_CASE("Test decorator parser on style", "[unit-test]")
TEST_CASE("Test decorator parser on aggregation", "[unit-test]") TEST_CASE("Test decorator parser on aggregation", "[unit-test]")
{ {
std::string comment = R"( std::string comment = R"(
\clanguml{aggregation[0..1:0..*]} \uml{aggregation[0..1:0..*]}
)"; )";
using namespace clanguml::decorators; using namespace clanguml::decorators;
@@ -127,7 +175,7 @@ TEST_CASE("Test decorator parser on aggregation", "[unit-test]")
TEST_CASE("Test decorator parser on skip", "[unit-test]") TEST_CASE("Test decorator parser on skip", "[unit-test]")
{ {
std::string comment = R"( std::string comment = R"(
\clanguml{skip} \uml{skip}
)"; )";
using namespace clanguml::decorators; using namespace clanguml::decorators;
@@ -144,7 +192,7 @@ TEST_CASE("Test decorator parser on skip", "[unit-test]")
TEST_CASE("Test decorator parser on skiprelationship", "[unit-test]") TEST_CASE("Test decorator parser on skiprelationship", "[unit-test]")
{ {
std::string comment = R"( std::string comment = R"(
\clanguml{skiprelationship} \uml{skiprelationship}
)"; )";
using namespace clanguml::decorators; using namespace clanguml::decorators;
@@ -161,7 +209,7 @@ TEST_CASE("Test decorator parser on skiprelationship", "[unit-test]")
TEST_CASE("Test decorator parser on diagram scope", "[unit-test]") TEST_CASE("Test decorator parser on diagram scope", "[unit-test]")
{ {
std::string comment = R"( std::string comment = R"(
\clanguml{note:diagram1, diagram2, \uml{note:diagram1, diagram2,
diagram3[left] Note only for diagrams 1, 2 and 3.} diagram3[left] Note only for diagrams 1, 2 and 3.}
)"; )";