Skip to content

Commit 66e3e94

Browse files
committed
Reduce code duplication
1 parent 52b95f8 commit 66e3e94

File tree

4 files changed

+56
-85
lines changed

4 files changed

+56
-85
lines changed

src/htmldocvisitor.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,19 +2144,12 @@ void HtmlDocVisitor::startLink(const QCString &ref,const QCString &file,
21442144
m_t << "<a class=\"el\" ";
21452145
}
21462146
m_t << "href=\"";
2147-
if (!ref.isEmpty()) m_t << externalRef(relPath,ref,TRUE);
2148-
if (!file.isEmpty())
2149-
{
2150-
QCString fn = file;
2151-
addHtmlExtensionIfMissing(fn);
2152-
if (ref.isEmpty())
2153-
{
2154-
if (!anchor.isEmpty() && (m_fileName == Config_getString(HTML_OUTPUT) + "/" + fn)) fn = "";
2155-
else m_t << externalRef(relPath,ref,TRUE);
2156-
}
2157-
m_t << fn;
2158-
}
2159-
if (!anchor.isEmpty()) m_t << "#" << anchor;
2147+
QCString fn = file;
2148+
addHtmlExtensionIfMissing(fn);
2149+
m_t << createHtmlUrl(relPath,ref,true,
2150+
Config_getString(HTML_OUTPUT)+"/"+fn,
2151+
file,
2152+
anchor);
21602153
m_t << "\"";
21612154
if (!tooltip.isEmpty()) m_t << " title=\"" << convertToHtml(tooltip) << "\"";
21622155
m_t << ">";

src/htmlgen.cpp

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -892,19 +892,7 @@ void HtmlCodeGenerator::_writeCodeLink(const QCString &className,
892892
*m_t << "<a class=\"" << className << "\" ";
893893
}
894894
*m_t << "href=\"";
895-
if (!ref.isEmpty()) *m_t << externalRef(m_relPath,ref,TRUE);
896-
if (!f.isEmpty())
897-
{
898-
QCString fn = f;
899-
addHtmlExtensionIfMissing(fn);
900-
if (ref.isEmpty())
901-
{
902-
if (!anchor.isEmpty() && (fileName() == fn)) fn = "";
903-
else *m_t << externalRef(m_relPath,ref,TRUE);
904-
}
905-
*m_t << fn;
906-
}
907-
if (!anchor.isEmpty()) *m_t << "#" << anchor;
895+
*m_t << createHtmlUrl(m_relPath,ref,true,fileName(),f,anchor);
908896
*m_t << "\"";
909897
if (!tooltip.isEmpty()) *m_t << " title=\"" << convertToHtml(tooltip) << "\"";
910898
*m_t << ">";
@@ -920,22 +908,11 @@ void HtmlCodeGenerator::writeTooltip(const QCString &id, const DocLinkInfo &docI
920908
{
921909
*m_t << "<div class=\"ttc\" id=\"" << id << "\">";
922910
*m_t << "<div class=\"ttname\">";
923-
QCString url = docInfo.url;
924-
addHtmlExtensionIfMissing(url);
925911
if (!docInfo.url.isEmpty())
926912
{
927913
*m_t << "<a href=\"";
928-
if (!docInfo.ref.isEmpty()) *m_t << externalRef(m_relPath,docInfo.ref,TRUE);
929-
else
930-
{
931-
if (!docInfo.anchor.isEmpty() && (fileName() == url)) url = "";
932-
else *m_t << externalRef(m_relPath,docInfo.ref,TRUE);
933-
}
934-
*m_t << url;
935-
if (!docInfo.anchor.isEmpty())
936-
{
937-
*m_t << "#" << docInfo.anchor;
938-
}
914+
*m_t << createHtmlUrl(m_relPath,docInfo.ref,true,
915+
fileName(),docInfo.url,docInfo.anchor);
939916
*m_t << "\">";
940917
}
941918
docify(docInfo.name);
@@ -964,20 +941,9 @@ void HtmlCodeGenerator::writeTooltip(const QCString &id, const DocLinkInfo &docI
964941
*m_t << "<div class=\"ttdef\"><b>" << theTranslator->trDefinition() << "</b> ";
965942
if (!defInfo.url.isEmpty())
966943
{
967-
url = defInfo.url;
968-
addHtmlExtensionIfMissing(url);
969944
*m_t << "<a href=\"";
970-
if (!defInfo.ref.isEmpty()) *m_t << externalRef(m_relPath,defInfo.ref,TRUE);
971-
else
972-
{
973-
if (!defInfo.anchor.isEmpty() && (fileName() == url)) url = "";
974-
else *m_t << externalRef(m_relPath,defInfo.ref,TRUE);
975-
}
976-
*m_t << url;
977-
if (!defInfo.anchor.isEmpty())
978-
{
979-
*m_t << "#" << defInfo.anchor;
980-
}
945+
*m_t << createHtmlUrl(m_relPath,defInfo.ref,true,
946+
fileName(),defInfo.url,defInfo.anchor);
981947
*m_t << "\">";
982948
}
983949
*m_t << defInfo.file << ":" << defInfo.line;
@@ -992,20 +958,9 @@ void HtmlCodeGenerator::writeTooltip(const QCString &id, const DocLinkInfo &docI
992958
*m_t << "<div class=\"ttdecl\"><b>" << theTranslator->trDeclaration() << "</b> ";
993959
if (!declInfo.url.isEmpty())
994960
{
995-
url = declInfo.url;
996-
addHtmlExtensionIfMissing(url);
997961
*m_t << "<a href=\"";
998-
if (!declInfo.ref.isEmpty()) *m_t << externalRef(m_relPath,declInfo.ref,TRUE);
999-
else
1000-
{
1001-
if (!declInfo.anchor.isEmpty() && (fileName() == url)) url = "";
1002-
else *m_t << externalRef(m_relPath,declInfo.ref,TRUE);
1003-
}
1004-
*m_t << url;
1005-
if (!declInfo.anchor.isEmpty())
1006-
{
1007-
*m_t << "#" << declInfo.anchor;
1008-
}
962+
*m_t << createHtmlUrl(m_relPath,declInfo.ref,true,
963+
fileName(),declInfo.url,declInfo.anchor);
1009964
*m_t << "\">";
1010965
}
1011966
*m_t << declInfo.file << ":" << declInfo.line;
@@ -1749,19 +1704,10 @@ void HtmlGenerator::writeObjectLink(const QCString &ref,const QCString &f,
17491704
m_t << "<a class=\"el\" ";
17501705
}
17511706
m_t << "href=\"";
1752-
if (!ref.isEmpty()) m_t << externalRef(m_relPath,ref,TRUE);
1753-
if (!f.isEmpty())
1754-
{
1755-
QCString fn = f;
1756-
addHtmlExtensionIfMissing(fn);
1757-
if (ref.isEmpty())
1758-
{
1759-
if (!anchor.isEmpty() && (fileName() == Config_getString(HTML_OUTPUT) + "/" + fn)) fn = "";
1760-
else m_t << externalRef(m_relPath,ref,TRUE);
1761-
}
1762-
m_t << fn;
1763-
}
1764-
if (!anchor.isEmpty()) m_t << "#" << anchor;
1707+
QCString fn = f;
1708+
addHtmlExtensionIfMissing(fn);
1709+
m_t << createHtmlUrl(m_relPath,ref,true,
1710+
Config_getString(HTML_OUTPUT)+"/"+fn,f,anchor);
17651711
m_t << "\">";
17661712
docify(name);
17671713
m_t << "</a>";
@@ -1770,13 +1716,9 @@ void HtmlGenerator::writeObjectLink(const QCString &ref,const QCString &f,
17701716
void HtmlGenerator::startTextLink(const QCString &f,const QCString &anchor)
17711717
{
17721718
m_t << "<a href=\"";
1773-
if (!f.isEmpty())
1774-
{
1775-
QCString fn = f;
1776-
addHtmlExtensionIfMissing(fn);
1777-
if (anchor.isEmpty() || (fileName() != Config_getString(HTML_OUTPUT) + "/" + fn)) m_t << m_relPath << fn;
1778-
}
1779-
if (!anchor.isEmpty()) m_t << "#" << anchor;
1719+
QCString fn = f;
1720+
addHtmlExtensionIfMissing(fn);
1721+
m_t << createHtmlUrl("","",true,Config_getString(HTML_OUTPUT)+"/"+fn,f,anchor);
17801722
m_t << "\">";
17811723
}
17821724

src/util.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5825,6 +5825,36 @@ QCString externalLinkTarget(const bool parent)
58255825
return "";
58265826
}
58275827

5828+
QCString createHtmlUrl(const QCString &relPath,
5829+
const QCString &ref,
5830+
bool href,
5831+
const QCString &srcFileName,
5832+
const QCString &targetFileName,
5833+
const QCString &anchor)
5834+
{
5835+
QCString url;
5836+
if (!ref.isEmpty()) url = externalRef(relPath,ref,href);
5837+
if (!targetFileName.isEmpty())
5838+
{
5839+
QCString fn = targetFileName;
5840+
addHtmlExtensionIfMissing(fn);
5841+
if (ref.isEmpty())
5842+
{
5843+
if (!anchor.isEmpty() && srcFileName==fn)
5844+
{
5845+
fn=""; // omit file name for local links
5846+
}
5847+
else
5848+
{
5849+
url = relPath;
5850+
}
5851+
}
5852+
url+=fn;
5853+
}
5854+
if (!anchor.isEmpty()) url+="#"+anchor;
5855+
return url;
5856+
}
5857+
58285858
QCString externalRef(const QCString &relPath,const QCString &ref,bool href)
58295859
{
58305860
QCString result;

src/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ QCString filterTitle(const QCString &title);
398398
bool patternMatch(const FileInfo &fi,const StringVector &patList);
399399

400400
QCString externalLinkTarget(const bool parent = false);
401+
QCString createHtmlUrl(const QCString &relPath,
402+
const QCString &ref,
403+
bool href,
404+
const QCString &srcFileName,
405+
const QCString &targetFileName,
406+
const QCString &anchor);
401407
QCString externalRef(const QCString &relPath,const QCString &ref,bool href);
402408
int nextUtf8CharPosition(const QCString &utf8Str,uint32_t len,uint32_t startPos);
403409

0 commit comments

Comments
 (0)