Skip to content

Commit f4a9fe3

Browse files
committed
Renamed option to AUTOLINK_IGNORE_WORDS and modernized code a bit
1 parent bfe31b3 commit f4a9fe3

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/config.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,17 @@ Go to the <a href="commands.html">next</a> section or return to the
728728
or namespaces to their corresponding documentation. Such a link can be
729729
prevented in individual cases by putting a \c % sign in front of the word or
730730
globally by setting \c AUTOLINK_SUPPORT to \c NO. Words listed in the
731-
\c AUTOLINK_IGNORED_TOKENS tag are excluded from automatic linking.
731+
\c AUTOLINK_IGNORE_WORDS tag are excluded from automatic linking.
732732
]]>
733733
</docs>
734734
</option>
735-
<option type='list' id='AUTOLINK_IGNORED_TOKENS' format='string' depends='AUTOLINK_SUPPORT'>
735+
<option type='list' id='AUTOLINK_IGNORE_WORDS' format='string' depends='AUTOLINK_SUPPORT'>
736736
<docs>
737737
<![CDATA[
738-
This tag specifies a list of keywords that shall be ignored when generating
739-
links via the AUTOLINK_SUPPORT. This list does not affect affect links
740-
explictly created using the \# and the \\link .. \\endlink commands.
738+
This tag specifies a list of words that, when matching the start of a word in the documentation,
739+
will suppress auto links generation, if it is enabled via AUTOLINK_SUPPORT.
740+
This list does not affect affect links explictly created using \# or
741+
the \ref cmdlink "\\link" or \ref cmdref "\\ref" commands.
741742
]]>
742743
</docs>
743744
</option>

src/docparser.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -775,26 +775,19 @@ void DocParser::handleUnclosedStyleCommands()
775775
}
776776
}
777777

778-
bool DocParser::matchWord(const QCString &word,const StringVector &l)
779-
{
780-
for (const auto &s : l)
781-
{
782-
std::string prefix = s.substr(0,word.length());
783-
if (qstrcmp(prefix.c_str(),word)==0)
784-
{
785-
return TRUE;
786-
}
787-
}
788-
return FALSE;
789-
}
790-
791778
void DocParser::handleLinkedWord(DocNodeVariant *parent,DocNodeList &children,bool ignoreAutoLinkFlag)
792779
{
780+
// helper to check if word w starts with any of the words in AUTOLINK_IGNORE_WORDS
781+
auto ignoreWord = [](const QCString &w) -> bool {
782+
const auto &list = Config_getList(AUTOLINK_IGNORE_WORDS);
783+
return std::find_if(list.begin(), list.end(),
784+
[&w](const auto &ignore) { return w.startsWith(ignore); }
785+
)!=list.end();
786+
};
793787
QCString name = linkToText(context.lang,context.token->name,TRUE);
794788
AUTO_TRACE("word={}",name);
795789
bool autolinkSupport = Config_getBool(AUTOLINK_SUPPORT);
796-
if ((!autolinkSupport && !ignoreAutoLinkFlag)
797-
|| matchWord(context.token->name,Config_getList(AUTOLINK_IGNORED_TOKENS))) // no autolinking -> add as normal word
790+
if ((!autolinkSupport && !ignoreAutoLinkFlag) || ignoreWord(context.token->name)) // no autolinking -> add as normal word
798791
{
799792
children.append<DocWord>(this,parent,name);
800793
return;

src/docparser_p.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ class DocParser : public IDocParser
134134
void handleAnchor(DocNodeVariant *parent,DocNodeList &children);
135135
void handlePrefix(DocNodeVariant *parent,DocNodeList &children);
136136
void handleImage(DocNodeVariant *parent, DocNodeList &children);
137-
bool matchWord(const QCString &word,const StringVector &l);
138137
void readTextFileByName(const QCString &file,QCString &text);
139138

140139
std::stack< DocParserContext > contextStack;

src/qcstring.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@ class QCString
495495
return m_rep.rfind(s,0)==0; // looking "backward" starting and ending at index 0
496496
}
497497

498+
bool startsWith( const std::string &s) const
499+
{
500+
return m_rep.rfind(s,0)==0; // looking "backward" starting and ending at index 0
501+
}
502+
498503
bool startsWith( const QCString &s ) const
499504
{
500505
if (m_rep.empty() || s.isEmpty()) return s.isEmpty();
@@ -508,6 +513,12 @@ class QCString
508513
return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s, l)==0;
509514
}
510515

516+
bool endsWith(const std::string &s) const
517+
{
518+
size_t l = s.length();
519+
return m_rep.length()>=l && m_rep.compare(m_rep.length()-l, l, s)==0;
520+
}
521+
511522
bool endsWith(const QCString &s) const
512523
{
513524
size_t l = s.length();

0 commit comments

Comments
 (0)