37 auto isSpaceOrDot = [](
char c) {
return c==
' ' || c==
'\t' || c==
'\n' || c==
'.'; };
38 while (!s.empty() && isSpaceOrDot(s.back())) s.remove_suffix(1);
39 size_t end = s.length();
41 while (start>0 &&
isId(s[start-1])) start--;
42 if (start==
end)
return std::string();
45 std::string_view
prefix = s.substr(0,start);
47 auto endsWithKeyword = [&
prefix](std::string_view kw)
49 return prefix.length()>=kw.length() &&
53 bool hasKeyword = endsWithKeyword(
"class") || endsWithKeyword(
"typename") || endsWithKeyword(
"struct") || endsWithKeyword(
"record");
55 if (!hasKeyword && !(
prefix.empty() && lang!=SrcLangExt::Cpp))
return std::string();
57 return std::string(s.substr(start));
65 if (!name.empty()) names.push_back(std::move(name));
73 std::vector<std::string> names;
80 for (; d; d=d->getOuterScope())
110 addScopes(options.
self());
121 AUTO_TRACE(
"scope={} fileScope={} text={} autoBreak={} external={} keepSpaces={} indentLevel={}",
122 scope?scope->
name():
"",fileScope?fileScope->
name():
"",
124 if (text.
empty())
return;
127 std::string_view txtStr=text.
view();
128 size_t strLen = txtStr.length();
129 if (strLen==0)
return;
131 static const reg::Ex regExp(R
"((::)?\a[\w~!\\.:$"]*)");
142 size_t floatingIndex=0;
143 for (; it!=
end ; ++it)
145 const auto &match = *it;
146 size_t newIndex = match.position();
147 size_t matchLen = match.length();
148 floatingIndex+=newIndex-skipIndex+matchLen;
149 if (newIndex>0 && txtStr.at(newIndex-1)==
'0')
151 std::string_view part = txtStr.substr(skipIndex,newIndex+matchLen-skipIndex);
153 skipIndex=index=newIndex+matchLen;
158 bool insideString=
false;
159 for (
size_t i=index;i<newIndex;i++)
161 if (txtStr.at(i)==
'"') insideString=!insideString;
162 if (txtStr.at(i)==
'\\') i++;
169 std::string_view splitText = txtStr.substr(skipIndex,newIndex-skipIndex);
170 size_t splitLength = splitText.length();
172 size_t i = splitText.find(
',');
173 if (i==std::string::npos) { i=splitText.find(
'<');
if (i!=std::string::npos) offset=0; }
174 if (i==std::string::npos) { i=splitText.find(
"||");
if (i!=std::string::npos) offset=2; }
175 if (i==std::string::npos) { i=splitText.find(
"&&");
if (i!=std::string::npos) offset=2; }
176 if (i==std::string::npos) { i=splitText.find(
">>");
if (i!=std::string::npos) offset=2; }
177 if (i==std::string::npos) i=splitText.find(
'>');
178 if (i==std::string::npos) i=splitText.find(
' ');
180 if (i!=std::string::npos)
182 std::string_view part1 = splitText.substr(0,i+offset);
185 std::string_view part2 = splitText.substr(i+offset);
187 floatingIndex=splitLength-i-offset+matchLen;
197 std::string_view part = txtStr.substr(skipIndex,newIndex-skipIndex);
201 std::string_view word=txtStr.substr(newIndex,matchLen);
209 if (it1->name == matchWord)
218 if (!found && !templateNames.empty())
220 std::string_view plainWord = word;
221 while (!plainWord.empty() && plainWord.back()==
'.') plainWord.remove_suffix(1);
222 if (std::find(templateNames.begin(),templateNames.end(),plainWord)!=templateNames.end())
230 if (!insideString && !found)
255 auto writeCompoundName = [&](
const auto *cd_) {
256 if (options.
external() ? cd_->isLinkable() : cd_->isLinkableInProject())
261 out.
writeLink(cd_->getReference(),cd_->getOutputFileBase(),cd_->anchor(),word);
273 writeCompoundName(cd);
275 else if ((cd=
getClass(matchWord+
"-p")))
277 writeCompoundName(cd);
281 writeCompoundName(cnd);
285 writeCompoundName(d);
292 size_t m = matchWord.
rfind(
"::");
300 scopeName=scope->
name();
304 scopeName = matchWord.
left(m);
305 matchWord = matchWord.
mid(m+2);
314 if (result.
found && result.
md &&
321 if (result.
md!=self && (self==
nullptr || result.
md->
name()!=self->
name()))
350 skipIndex=index=newIndex+matchLen;
353 std::string_view lastPart = txtStr.substr(skipIndex);
This class contains the information about the argument of a function or template.
This class represents an function or template argument list.
A abstract class representing of a compound symbol.
virtual const ArgumentList & templateArguments() const =0
Returns the template arguments of this class.
virtual const ClassDef * templateMaster() const =0
Returns the template master of which this class is an instance.
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
size_t rfind(char c, size_t pos=npos) const
DString mid(size_t index, size_t len=npos) const
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
std::string_view view() const
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
DString left(size_t len) const
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
The common base class of all entity definitions found in the sources.
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual bool isLinkable() const =0
virtual DefType definitionType() const =0
virtual const DString & name() const =0
virtual bool isLinkableInProject() const =0
virtual DString qualifiedName() const =0
virtual DString anchor() const =0
virtual DString getReference() const =0
virtual Definition * getOuterScope() const =0
virtual DString getOutputFileBase() const =0
A model of a file symbol.
A model of a class/file/namespace member symbol.
virtual const ArgumentList & templateArguments() const =0
virtual const ArgumentLists & definitionTemplateParameterLists() const =0
virtual bool isVariable() const =0
const ClassDef * resolveClass(const Definition *scope, const DString &name, bool maybeUnlinkable=false, bool mayBeHidden=false)
Find the class definition matching name within the scope set.
const Definition * resolveSymbol(const Definition *scope, const DString &name, const DString &args=DString(), bool checkCV=false, bool insideCode=false, bool onlyLinkable=false)
Find the symbool definition matching name within the scope set.
const MemberDef * getTypedef() const
In case a call to resolveClass() resolves to a type member (e.g. an enum) this method will return it.
Abstract interface for a hyperlinked text fragment.
virtual void writeString(std::string_view, bool) const =0
virtual void writeBreak(int indent) const =0
virtual void writeLink(const DString &extRef, const DString &file, const DString &anchor, std::string_view text) const =0
ClassDef * getClass(const DString &n)
ClassDef * toClassDef(Definition *d)
Class representing a regular expression.
Class to iterate through matches.
ConceptDef * getConcept(const DString &n)
ConceptDef * toConceptDef(Definition *d)
DirIterator end(const DirIterator &) noexcept
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
bool isId(char c)
Returns true if c is a valid character for an identifier.
static void addTemplateParameterNames(const ArgumentList &al, SrcLangExt lang, std::vector< std::string > &names)
static std::string templateParameterName(const Argument &a, SrcLangExt lang)
void linkifyText(const TextGeneratorIntf &out, const DString &text, const LinkifyTextOptions &options)
static std::vector< std::string > getTemplateParameterNames(const LinkifyTextOptions &options)
MemberDef * toMemberDef(Definition *d)
const ArgumentList * argumentList() const
const Definition * scope() const
const Definition * self() const
size_t breakThreshold() const
const FileDef * fileScope() const
const std::vector< const ArgumentList * > & templateArgumentLists() const
GetDefResult getDefs(const GetDefInput &input)
A bunch of utility functions.