Skip to content

Commit 5d929c3

Browse files
committed
DotAttributes based on map
1 parent 1e5aa12 commit 5d929c3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/dotgraph.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <sstream>
1717
#include <mutex>
18+
#include <regex>
1819

1920
#include "config.h"
2021
#include "doxygen.h"
@@ -103,6 +104,38 @@ static bool insertMapFile(TextStream &out,const QCString &mapFile,
103104

104105
//--------------------------------------------------------------------
105106

107+
DotAttributes::DotAttributes(QCString input)
108+
{
109+
std::string tag = R"(\s*(\w+)\s*)";
110+
std::string unquoted = R"(\s*([^\s,"]+)\s*)";
111+
std::string quoted = R"(\s*\"([^"]*)\"\s*)";
112+
113+
std::regex re(tag + "=" + "(?:" + unquoted + "|" + quoted + "),?(.*)");
114+
115+
std::map<QCString, QCString> res;
116+
while (!input.isEmpty()) {
117+
std::smatch res1;
118+
if (!std::regex_match(input.str(), res1, re)) {
119+
(*this)["_unmatched_"] = input;
120+
break;
121+
}
122+
// with or without quotes
123+
(*this)[QCString(res1[1])] = res1[2].str() + res1[3].str();
124+
input = res1[4]; // the rest
125+
}
126+
}
127+
128+
QCString DotAttributes::str()
129+
{
130+
QCString s;
131+
for (auto kv: *this) {
132+
if (s.length())
133+
s += ' ';
134+
s += kv.first + QCString("=") + kv.second.quoted();
135+
}
136+
return s;
137+
}
138+
106139
QCString DotGraph::imgName() const
107140
{
108141
return m_baseName + ((m_graphFormat == GOF_BITMAP) ?

src/dotgraph.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define DOTGRAPH_H
1818

1919
#include <iostream>
20+
#include <map>
2021

2122
#include "qcstring.h"
2223
#include "dir.h"
@@ -28,6 +29,12 @@ enum GraphOutputFormat { GOF_BITMAP, GOF_EPS };
2829
enum EmbeddedOutputFormat { EOF_Html, EOF_LaTeX, EOF_Rtf, EOF_DocBook };
2930
enum GraphType { Dependency, Inheritance, Collaboration, Hierarchy, CallGraph };
3031

32+
struct DotAttributes : std::map<QCString, QCString>
33+
{
34+
DotAttributes(QCString input);
35+
QCString str();
36+
};
37+
3138
/** A dot graph */
3239
class DotGraph
3340
{

0 commit comments

Comments
 (0)