Skip to content

Commit e099909

Browse files
committed
PR #11500 Code simplifications
1 parent df273ec commit e099909

File tree

7 files changed

+61
-87
lines changed

7 files changed

+61
-87
lines changed

src/docbookvisitor.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,13 @@ DB_VIS_C
433433
case DocVerbatim::PlantUML:
434434
{
435435
QCString docbookOutput = Config_getString(DOCBOOK_OUTPUT);
436-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(docbookOutput,
436+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(docbookOutput,
437437
s.exampleFile(),s.text(),PlantumlManager::PUML_BITMAP,
438438
s.engine(),s.srcFile(),s.srcLine(),true);
439-
for(const auto &baseName: baseNameVector)
439+
for (const auto &baseName: baseNameVector)
440440
{
441-
QCString shortName = makeShortName(baseName);
442441
m_t << "<para>\n";
443-
writePlantUMLFile(baseName,s);
442+
writePlantUMLFile(QCString(baseName),s);
444443
m_t << "</para>\n";
445444
}
446445
}
@@ -1580,12 +1579,12 @@ DB_VIS_C
15801579
QCString outDir = Config_getString(DOCBOOK_OUTPUT);
15811580
std::string inBuf;
15821581
readInputFile(fileName,inBuf);
1583-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(outDir,
1584-
QCString(),inBuf.c_str(),PlantumlManager::PUML_BITMAP,QCString(),srcFile,srcLine,false);
1582+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(outDir,
1583+
QCString(),inBuf.c_str(),PlantumlManager::PUML_BITMAP,QCString(),srcFile,srcLine,false);
15851584
bool first = true;
1586-
for(auto &baseName: baseNameVector)
1585+
for (const auto &bName: baseNameVector)
15871586
{
1588-
baseName=makeBaseName(baseName);
1587+
QCString baseName=makeBaseName(QCString(bName));
15891588
PlantumlManager::instance().generatePlantUMLOutput(baseName,outDir,PlantumlManager::PUML_BITMAP);
15901589
if (!first) endPlantUmlFile(hasCaption);
15911590
first = false;

src/htmldocvisitor.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,13 @@ void HtmlDocVisitor::operator()(const DocVerbatim &s)
690690
{
691691
format = PlantumlManager::PUML_SVG;
692692
}
693-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(
693+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
694694
htmlOutput,s.exampleFile(),
695695
s.text(),format,s.engine(),s.srcFile(),s.srcLine(),true);
696-
for(const auto &baseName: baseNameVector)
696+
for (const auto &baseName: baseNameVector)
697697
{
698698
m_t << "<div class=\"plantumlgraph\">\n";
699-
writePlantUMLFile(baseName,s.relPath(),s.context(),s.srcFile(),s.srcLine());
699+
writePlantUMLFile(QCString(baseName),s.relPath(),s.context(),s.srcFile(),s.srcLine());
700700
visitCaption(m_t, s);
701701
m_t << "</div>\n";
702702
}
@@ -1852,12 +1852,11 @@ void HtmlDocVisitor::operator()(const DocPlantUmlFile &df)
18521852
}
18531853
std::string inBuf;
18541854
readInputFile(df.file(),inBuf);
1855-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(
1856-
htmlOutput,QCString(),
1855+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(htmlOutput,QCString(),
18571856
inBuf.c_str(),format,QCString(),df.srcFile(),df.srcLine(),false);
1858-
for(auto &baseName: baseNameVector)
1857+
for (const auto &bName: baseNameVector)
18591858
{
1860-
baseName=makeBaseName(baseName);
1859+
QCString baseName=makeBaseName(QCString(bName));
18611860
m_t << "<div class=\"plantumlgraph\">\n";
18621861
writePlantUMLFile(baseName,df.relPath(),QCString(),df.srcFile(),df.srcLine());
18631862
if (df.hasCaption())

src/latexdocvisitor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,14 @@ void LatexDocVisitor::operator()(const DocVerbatim &s)
550550
case DocVerbatim::PlantUML:
551551
{
552552
QCString latexOutput = Config_getString(LATEX_OUTPUT);
553-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(
553+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
554554
latexOutput,s.exampleFile(),s.text(),
555555
s.useBitmap() ? PlantumlManager::PUML_BITMAP : PlantumlManager::PUML_EPS,
556556
s.engine(),s.srcFile(),s.srcLine(),true);
557557

558-
for(const auto &baseName: baseNameVector)
558+
for (const auto &baseName: baseNameVector)
559559
{
560-
writePlantUMLFile(baseName, s);
560+
writePlantUMLFile(QCString(baseName), s);
561561
}
562562
}
563563
break;
@@ -2122,14 +2122,14 @@ void LatexDocVisitor::startPlantUmlFile(const QCString &fileName,
21222122
readInputFile(fileName,inBuf);
21232123

21242124
bool useBitmap = inBuf.find("@startditaa") != std::string::npos;
2125-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(
2125+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
21262126
outDir,QCString(),inBuf.c_str(),
21272127
useBitmap ? PlantumlManager::PUML_BITMAP : PlantumlManager::PUML_EPS,
21282128
QCString(),srcFile,srcLine,false);
21292129
bool first = true;
2130-
for(auto &baseName: baseNameVector)
2130+
for (const auto &bName: baseNameVector)
21312131
{
2132-
baseName=makeBaseName(baseName);
2132+
QCString baseName = makeBaseName(QCString(bName));
21332133
QCString shortName = makeShortName(baseName);
21342134
if (useBitmap)
21352135
{

src/plantuml.cpp

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
static std::mutex g_PlantUmlMutex;
3030

31-
std::vector<QCString> PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
31+
StringVector PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
3232
const QCString &content,OutputFormat format, const QCString &engine,
3333
const QCString &srcFile,int srcLine,bool inlineCode)
3434
{
35-
std::vector<QCString> baseNameVector;
35+
StringVector baseNameVector;
3636
QCString baseName;
3737
QCString puName;
3838
QCString imgName;
@@ -83,60 +83,37 @@ std::vector<QCString> PlantumlManager::writePlantUMLSource(const QCString &outDi
8383
locEngine += c;
8484
text+=c;
8585
}
86-
QCString line;
87-
// get everything till end or endOfLine
88-
if (c && (c!='\n'))
89-
{
90-
line += c;
91-
while ((c=*p++) && (c!='\n')) line+=c;
92-
line = line.stripWhiteSpace();
93-
}
9486
QCString inpName;
9587
QCString rest;
96-
// REGEXP (<fn>)(<ext>?)(<rest>)
97-
static const reg::Ex re_new0(R"((([A-Za-z0-9_][A-Za-z0-9_-]*)))");
98-
static const reg::Ex re_new1(R"((([A-Za-z0-9_][A-Za-z0-9_-]*)(\.[A-Za-z0-9_][A-Za-z0-9_-]*)))");
99-
static const reg::Ex re_new2(R"((([A-Za-z0-9_][A-Za-z0-9_-]*)(\.[A-Za-z0-9_][A-Za-z0-9_-]*)(.*)))");
100-
static const reg::Ex re_new3(R"(([A-Za-z0-9_][A-Za-z0-9_-]*)(.*))");
101-
//std::string_view txtStr = line.view();
102-
if (!line.isEmpty())
88+
89+
// skip leading whitespace
90+
if (*p && (c==' ' || c=='\t'))
10391
{
104-
reg::Match match0;
105-
reg::Match match1;
106-
reg::Match match2;
107-
reg::Match match3;
108-
bool matchSet = false;
109-
if (matchSet = reg::match(line.str(),match0,re_new0))
110-
{
111-
inpName = match0[1].str();
112-
}
113-
else if (matchSet = reg::match(line.str(),match1,re_new1))
114-
{
115-
inpName = match1[1].str();
116-
}
117-
else if (matchSet = reg::match(line.str(),match2,re_new2))
118-
{
119-
inpName = match2[1].str();
120-
rest = match2[3].str();
121-
}
122-
else if (matchSet = reg::match(line.str(),match3,re_new3))
123-
{
124-
inpName = match3[1].str();
125-
rest = match3[2].str();
126-
}
127-
if (matchSet)
128-
{
129-
generatePlantUmlFileNames(inpName,format,outDir,baseName,puName,imgName);
130-
}
131-
else
132-
{
133-
generatePlantUmlFileNames(QCString(),format,outDir,baseName,puName,imgName);
134-
}
92+
while ((c=*p++) && (c==' ' || c=='\t')) {}
13593
}
136-
else
94+
// get everything till end or endOfLine, and split into inpName (without extension) and rest
95+
enum State { InName, InExt, InRest };
96+
State state = InName;
97+
while (*p && c!='\n')
13798
{
138-
generatePlantUmlFileNames(QCString(),format,outDir,baseName,puName,imgName);
99+
switch (state)
100+
{
101+
case InName: // looking for the name part
102+
if (isId(c) || c=='-') inpName+=c;
103+
else if (c=='.') state=InExt;
104+
else rest+=c, state=InRest;
105+
break;
106+
case InExt: // skipping over extension part
107+
if (!isId(c) && c!='-') rest+=c, state=InRest;
108+
break;
109+
case InRest: // gather rest until new line
110+
rest+=c;
111+
break;
112+
}
113+
c = *p++;
139114
}
115+
//printf("inpName='%s' rest='%s'\n",qPrint(inpName),qPrint(rest));
116+
generatePlantUmlFileNames(inpName,format,outDir,baseName,puName,imgName);
140117

141118
// insert the image name
142119
text+=' ';
@@ -161,7 +138,7 @@ std::vector<QCString> PlantumlManager::writePlantUMLSource(const QCString &outDi
161138
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
162139
PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text,srcFile,srcLine);
163140
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
164-
baseNameVector.emplace_back(baseName);
141+
baseNameVector.push_back(baseName.str());
165142
text.clear();
166143
}
167144
}
@@ -182,7 +159,7 @@ std::vector<QCString> PlantumlManager::writePlantUMLSource(const QCString &outDi
182159
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
183160
PlantumlManager::instance().insert(generateType.str(),puName.str(),outDir,format,text,srcFile,srcLine);
184161
Debug::print(Debug::Plantuml,0,"*** writePlantUMLSource generateType: {}\n",generateType);
185-
baseNameVector.emplace_back(baseName);
162+
baseNameVector.push_back(baseName.str());
186163
}
187164

188165
return baseNameVector;

src/plantuml.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include <map>
2020
#include <string>
21-
#include <vector>
2221

2322
#include "containers.h"
2423
#include "qcstring.h"
@@ -61,10 +60,10 @@ class PlantumlManager
6160
* from the `\planumlfile` command (`false`)
6261
* @returns The names of the generated files.
6362
*/
64-
std::vector<QCString> writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
65-
const QCString &content, OutputFormat format,
66-
const QCString &engine,const QCString &srcFile,
67-
int srcLine,bool inlineCode);
63+
StringVector writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
64+
const QCString &content, OutputFormat format,
65+
const QCString &engine,const QCString &srcFile,
66+
int srcLine,bool inlineCode);
6867

6968
/** Convert a PlantUML file to an image.
7069
* @param[in] baseName the name of the generated file (as returned by writePlantUMLSource())

src/rtfdocvisitor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,13 @@ void RTFDocVisitor::operator()(const DocVerbatim &s)
426426
case DocVerbatim::PlantUML:
427427
{
428428
QCString rtfOutput = Config_getString(RTF_OUTPUT);
429-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(
429+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
430430
rtfOutput,s.exampleFile(),s.text(),PlantumlManager::PUML_BITMAP,
431431
s.engine(),s.srcFile(),s.srcLine(),true);
432432

433-
for(const auto &baseName: baseNameVector)
433+
for (const auto &baseName: baseNameVector)
434434
{
435-
writePlantUMLFile(baseName, s.hasCaption());
435+
writePlantUMLFile(QCString(baseName), s.hasCaption());
436436
visitChildren(s);
437437
includePicturePostRTF(true, s.hasCaption());
438438
}
@@ -1323,12 +1323,12 @@ void RTFDocVisitor::operator()(const DocPlantUmlFile &df)
13231323
QCString rtfOutput = Config_getString(RTF_OUTPUT);
13241324
std::string inBuf;
13251325
readInputFile(df.file(),inBuf);
1326-
std::vector<QCString> baseNameVector = PlantumlManager::instance().writePlantUMLSource(
1326+
auto baseNameVector = PlantumlManager::instance().writePlantUMLSource(
13271327
rtfOutput,QCString(),inBuf.c_str(),PlantumlManager::PUML_BITMAP,
13281328
QCString(),df.srcFile(),df.srcLine(),false);
1329-
for(auto &baseName: baseNameVector)
1329+
for(const auto &baseName: baseNameVector)
13301330
{
1331-
writePlantUMLFile(baseName, df.hasCaption());
1331+
writePlantUMLFile(QCString(baseName), df.hasCaption());
13321332
visitChildren(df);
13331333
includePicturePostRTF(true, df.hasCaption());
13341334
}

src/vhdldocgen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,10 +3009,10 @@ void FlowChart::printUmlTree()
30093009
QCString htmlOutDir = Config_getString(HTML_OUTPUT);
30103010

30113011
QCString n=convertNameToFileName();
3012-
std::vector<QCString> baseNameVector=PlantumlManager::instance().writePlantUMLSource(htmlOutDir,n,qcs,PlantumlManager::PUML_SVG,"uml",n,1,true);
3013-
for(const auto &baseName: baseNameVector)
3012+
auto baseNameVector=PlantumlManager::instance().writePlantUMLSource(htmlOutDir,n,qcs,PlantumlManager::PUML_SVG,"uml",n,1,true);
3013+
for (const auto &baseName: baseNameVector)
30143014
{
3015-
PlantumlManager::instance().generatePlantUMLOutput(baseName,htmlOutDir,PlantumlManager::PUML_SVG);
3015+
PlantumlManager::instance().generatePlantUMLOutput(QCString(baseName),htmlOutDir,PlantumlManager::PUML_SVG);
30163016
}
30173017
}
30183018

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy