117{
121 AUTO_TRACE(
"scope={} fileScope={} text={} autoBreak={} external={} keepSpaces={} indentLevel={}",
122 scope?scope->
name():
"",fileScope?fileScope->
name():
"",
124 if (text.
empty())
return;
125
126
127 std::string_view txtStr=text.
view();
128 size_t strLen = txtStr.length();
129 if (strLen==0) return;
130
131 static const reg::Ex regExp(R
"((::)?\a[\w~!\\.:$"]*)");
134
135
136
137
138
140 size_t index=0;
141 size_t skipIndex=0;
142 size_t floatingIndex=0;
143 for (; it!=
end ; ++it)
144 {
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')
150 {
151 std::string_view part = txtStr.substr(skipIndex,newIndex+matchLen-skipIndex);
153 skipIndex=index=newIndex+matchLen;
154 continue;
155 }
156
157
158 bool insideString=false;
159 for (size_t i=index;i<newIndex;i++)
160 {
161 if (txtStr.at(i)=='"') insideString=!insideString;
162 if (txtStr.at(i)=='\\') i++;
163 }
164
165
168 {
169 std::string_view splitText = txtStr.substr(skipIndex,newIndex-skipIndex);
170 size_t splitLength = splitText.length();
171 size_t offset=1;
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(' ');
179
180 if (i!=std::string::npos)
181 {
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;
188 }
189 else
190 {
191 out.writeString(splitText,options.
keepSpaces());
192 }
193 }
194 else
195 {
196
197 std::string_view part = txtStr.substr(skipIndex,newIndex-skipIndex);
199 }
200
201 std::string_view word=txtStr.substr(newIndex,matchLen);
203 bool found=false;
204
206 {
208 {
209 if (it1->name == matchWord)
210 {
212 found = true;
213 break;
214 }
215 }
216 }
217
218 if (!found && !templateNames.empty())
219 {
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())
223 {
225 found = true;
226 }
227 }
228
229
230 if (!insideString && !found)
231 {
235
236
238 cd=resolver.resolveClass(scope,matchWord);
239 const MemberDef *typeDef = resolver.getTypedef();
240 if (typeDef)
241 {
243 {
245 {
246
250 word);
251 found=true;
252 }
253 }
254 }
255 auto writeCompoundName = [&](const auto *cd_) {
256 if (options.
external() ? cd_->isLinkable() : cd_->isLinkableInProject())
257 {
258 if (self==
nullptr || cd_->qualifiedName()!=self->
qualifiedName())
259 {
260
261 out.writeLink(cd_->getReference(),cd_->getOutputFileBase(),cd_->anchor(),word);
262 found=true;
263 }
264 }
265 };
266
267 if (found)
268 {
269
270 }
272 {
273 writeCompoundName(cd);
274 }
275 else if ((cd=
getClass(matchWord+
"-p")))
276 {
277 writeCompoundName(cd);
278 }
280 {
281 writeCompoundName(cnd);
282 }
283 else if ((d=resolver.resolveSymbol(scope,matchWord)))
284 {
285 writeCompoundName(d);
286 }
287 else
288 {
289
290 }
291
292 size_t m = matchWord.
rfind(
"::");
294 if (scope &&
297 )
298 )
299 {
300 scopeName=scope->
name();
301 }
303 {
304 scopeName = matchWord.
left(m);
305 matchWord = matchWord.
mid(m+2);
306 }
307
308
309
310 if (!found)
311 {
314 if (result.
found && result.
md &&
316 )
317 {
318
319
320
321 if (result.
md!=self && (self==
nullptr || result.
md->
name()!=self->
name()))
322
323 {
324
325
326
327 if (!(scope &&
331 )
332 )
333 {
334
337 found=true;
338 }
339 }
340 }
341 }
342 }
343
344 if (!found)
345 {
347 }
348
349
350 skipIndex=index=newIndex+matchLen;
351 }
352
353 std::string_view lastPart = txtStr.substr(skipIndex);
354 out.writeString(lastPart,options.
keepSpaces());
355}
A abstract class representing of a compound symbol.
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 bool isVariable() const =0
ClassDef * getClass(const DString &n)
Class representing a regular expression.
Class to iterate through matches.
ConceptDef * getConcept(const DString &n)
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
static std::vector< std::string > getTemplateParameterNames(const LinkifyTextOptions &options)
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
const ArgumentList * argumentList() const
const Definition * scope() const
const Definition * self() const
size_t breakThreshold() const
const FileDef * fileScope() const
GetDefResult getDefs(const GetDefInput &input)