summaryrefslogtreecommitdiffstats
path: root/src/util.cpp
diff options
context:
space:
mode:
authorDimitri van Heesch <doxygen@gmail.com>2021-02-12 19:36:47 (GMT)
committerDimitri van Heesch <doxygen@gmail.com>2021-02-20 18:23:52 (GMT)
commite3360f7b9ddff7ba3247ea1bbdb681fddc5a5afd (patch)
treede7e5a2655c31b90e99c64f10c4681d4fa1efec9 /src/util.cpp
parentb800b3c6f464e0d5f86fa68c710426779cf9ba44 (diff)
downloadDoxygen-e3360f7b9ddff7ba3247ea1bbdb681fddc5a5afd.zip
Doxygen-e3360f7b9ddff7ba3247ea1bbdb681fddc5a5afd.tar.gz
Doxygen-e3360f7b9ddff7ba3247ea1bbdb681fddc5a5afd.tar.bz2
Refactoring: reduce code duplication by using writeMarkerList function
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/util.cpp b/src/util.cpp
index a7f4630..5f3dd8e 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1093,13 +1093,11 @@ void linkifyText(const TextGeneratorIntf &out, const Definition *scope,
out.writeString(lastPart.c_str(),keepSpaces);
}
-
-void writeExamples(OutputList &ol,const ExampleList &list)
+void writeMarkerList(OutputList &ol,const std::string &markerText,size_t numMarkers,
+ std::function<void(OutputList &ol,size_t index)> replaceFunc)
{
- std::string exampleLine=theTranslator->trWriteList((int)list.size()).str();
-
static std::regex marker("@[[:digit:]]+");
- std::sregex_iterator it(exampleLine.begin(),exampleLine.end(),marker);
+ std::sregex_iterator it(markerText.begin(),markerText.end(),marker);
std::sregex_iterator end;
size_t index=0;
// now replace all markers in inheritLine with links to the classes
@@ -1108,32 +1106,42 @@ void writeExamples(OutputList &ol,const ExampleList &list)
const auto &match = *it;
size_t newIndex = match.position();
size_t matchLen = match.length();
- auto prefixPart = exampleLine.substr(index,newIndex-index);
- ol.parseText(prefixPart);
+ ol.parseText(markerText.substr(index,newIndex-index));
unsigned long entryIndex = std::stoul(match.str().substr(1));
- if (entryIndex<(unsigned long)list.size())
+ if (entryIndex<(unsigned long)numMarkers)
{
- const auto &e = list[entryIndex];
- ol.pushGeneratorState();
- ol.disable(OutputGenerator::Latex);
- ol.disable(OutputGenerator::RTF);
- ol.disable(OutputGenerator::Docbook);
- // link for Html / man
- //printf("writeObjectLink(file=%s)\n",e->file.data());
- ol.writeObjectLink(0,e.file,e.anchor,e.name);
- ol.popGeneratorState();
-
- ol.pushGeneratorState();
- ol.disable(OutputGenerator::Man);
- ol.disable(OutputGenerator::Html);
- // link for Latex / pdf with anchor because the sources
- // are not hyperlinked (not possible with a verbatim environment).
- ol.writeObjectLink(0,e.file,0,e.name);
- ol.popGeneratorState();
+ replaceFunc(ol,entryIndex);
}
index=newIndex+matchLen;
}
- ol.parseText(exampleLine.substr(index));
+ ol.parseText(markerText.substr(index));
+}
+
+void writeExamples(OutputList &ol,const ExampleList &list)
+{
+ auto replaceFunc = [&list](OutputList &ol,size_t entryIndex)
+ {
+ const auto &e = list[entryIndex];
+ ol.pushGeneratorState();
+ ol.disable(OutputGenerator::Latex);
+ ol.disable(OutputGenerator::RTF);
+ ol.disable(OutputGenerator::Docbook);
+ // link for Html / man
+ //printf("writeObjectLink(file=%s)\n",e->file.data());
+ ol.writeObjectLink(0,e.file,e.anchor,e.name);
+ ol.popGeneratorState();
+
+ ol.pushGeneratorState();
+ ol.disable(OutputGenerator::Man);
+ ol.disable(OutputGenerator::Html);
+ // link for Latex / pdf with anchor because the sources
+ // are not hyperlinked (not possible with a verbatim environment).
+ ol.writeObjectLink(0,e.file,0,e.name);
+ ol.popGeneratorState();
+ };
+
+ writeMarkerList(ol, theTranslator->trWriteList((int)list.size()).str(), list.size(), replaceFunc);
+
ol.writeString(".");
}