Doxygen
Loading...
Searching...
No Matches
searchindex_js.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2022 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16// own header
17#include "searchindex_js.h"
18
19// standard includes
20#include <algorithm>
21#include <utility>
22
23// other includes
24#include "classdef.h"
25#include "classlist.h"
26#include "conceptdef.h"
27#include "docparser.h"
28#include "doxygen.h"
29#include "filename.h"
30#include "groupdef.h"
31#include "indexlist.h"
32#include "language.h"
33#include "membername.h"
34#include "message.h"
35#include "moduledef.h"
36#include "namespacedef.h"
37#include "pagedef.h"
38#include "portable.h"
39#include "resourcemgr.h"
40#include "section.h"
41#include "textstream.h"
42#include "threadpool.h"
43#include "util.h"
44
46{
47 if (std::holds_alternative<const Definition *>(info))
48 {
49 const Definition *def = std::get<const Definition *>(info);
51 title = type==Definition::TypeGroup ? parseCommentAsHtml(def,nullptr,toGroupDef(def)->groupTitle(),def->getDefFileName(),def->getDefLine()) :
52 type==Definition::TypePage ? parseCommentAsHtml(def,nullptr,toPageDef(def)->title(),def->getDefFileName(),def->getDefLine()) :
53 def->localName();
54 }
55 else if (std::holds_alternative<const SectionInfo *>(info))
56 {
57 const SectionInfo *si = std::get<const SectionInfo *>(info);
58 title = parseCommentAsHtml(si->definition(),nullptr,si->title(),si->fileName(),si->lineNr());
59 }
60 else
61 {
62 ASSERT(false);
63 }
64}
65
67{
68 TextStream t;
69
70 for (size_t i=0;i<word.length();i++)
71 {
72 char c = word.at(i);
73 if (static_cast<signed char>(c)<0 || isalnum(c))
74 {
75 t << word.at(i);
76 }
77 else // escape non-identifier characters
78 {
79 static const char *hex = "0123456789ABCDEF";
80 unsigned char uc = static_cast<unsigned char>(word.at(i));
81 t << '_';
82 t << hex[uc>>4];
83 t << hex[uc&0xF];
84 }
85 }
86
87 return convertUTF8ToLower(t.str());
88}
89
90//-------------------------------------------------------------------------------------------
91
92//! helper function to simplify the given title string, and fill a list of start positions
93//! for the start of each word in the simplified title string.
94static void splitSearchTokens(DString &title,SizeVector &indices)
95{
96 if (title.empty()) return;
97
98 // simplify title to contain only words with single space as separator
99 size_t di=0;
100 bool lastIsSpace=true;
101 for (size_t si=0; si<title.length(); si++)
102 {
103 char c = title.at(si);
104 if (c=='@' || c=='\\') // skip over special commands
105 {
106 title.at(di)=' ';
107 if (si<title.length()-1)
108 {
109 c = title.at(++si);
110 while (si<title.length() && (isId(c) || c==':')) c = title.at(++si);
111 --si;
112 }
113 }
114 else if (c=='<') // skip over html tags
115 {
116 if (si<title.length()-1)
117 {
118 for (size_t tsi = si; tsi<title.length(); ++tsi)
119 {
120 if (title.at(tsi)=='>')
121 {
122 si=tsi;
123 break;
124 }
125 }
126 }
127 }
128 else if (isId(c) || c==':') // add "word" character
129 {
130 title.at(di)=c;
131 di++;
132 lastIsSpace=false;
133 }
134 else if (!lastIsSpace) // add one separator as space
135 {
136 title.at(di)=' ';
137 di++;
138 lastIsSpace=true;
139 }
140 }
141 if (di>0 && title.at(di-1)==' ') di--; // strip trailing whitespace
142 title.resize(di);
143
144 // create a list of start positions within title for
145 // each unique word in order of appearance
146 size_t p=0,i=0;
147 while ((i=title.find(' ',p))!=DString::npos)
148 {
149 std::string word = title.mid(p,i-p).str();
150 indices.push_back(p);
151 p = i+1;
152 }
153 if (p<title.length())
154 {
155 std::string word = title.mid(p).str();
156 indices.push_back(p);
157 }
158}
159
160//-------------------------------------------------------------------------------------------
161
162#define SEARCH_INDEX_ALL 0
163#define SEARCH_INDEX_CLASSES 1
164#define SEARCH_INDEX_INTERFACES 2
165#define SEARCH_INDEX_STRUCTS 3
166#define SEARCH_INDEX_EXCEPTIONS 4
167#define SEARCH_INDEX_NAMESPACES 5
168#define SEARCH_INDEX_FILES 6
169#define SEARCH_INDEX_FUNCTIONS 7
170#define SEARCH_INDEX_VARIABLES 8
171#define SEARCH_INDEX_TYPEDEFS 9
172#define SEARCH_INDEX_SEQUENCES 10
173#define SEARCH_INDEX_DICTIONARIES 11
174#define SEARCH_INDEX_ENUMS 12
175#define SEARCH_INDEX_ENUMVALUES 13
176#define SEARCH_INDEX_PROPERTIES 14
177#define SEARCH_INDEX_EVENTS 15
178#define SEARCH_INDEX_RELATED 16
179#define SEARCH_INDEX_DEFINES 17
180#define SEARCH_INDEX_GROUPS 18
181#define SEARCH_INDEX_PAGES 19
182#define SEARCH_INDEX_CONCEPTS 20
183#define SEARCH_INDEX_MODULES 21
184#define SEARCH_INDEX_RECORDS 22
185
186static std::array<SearchIndexInfo,NUM_SEARCH_INDICES> g_searchIndexInfo =
187{ {
188 // index name getText symbolList
189 { /* SEARCH_INDEX_ALL */ "all" , []() { return theTranslator->trAll(); }, {} },
190 { /* SEARCH_INDEX_CLASSES */ "classes" , []() { return theTranslator->trClasses(); }, {} },
191 { /* SEARCH_INDEX_INTERFACES */ "interfaces" , []() { return theTranslator->trSliceInterfaces(); }, {} },
192 { /* SEARCH_INDEX_STRUCTS */ "structs" , []() { return theTranslator->trStructs(); }, {} },
193 { /* SEARCH_INDEX_RECORDS */ "records" , []() { return theTranslator->trRecords(); }, {} },
194 { /* SEARCH_INDEX_EXCEPTIONS */ "exceptions" , []() { return theTranslator->trExceptions(); }, {} },
195 { /* SEARCH_INDEX_NAMESPACES */ "namespaces" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
197 theTranslator->trNamespace(true,false); }, {} },
198 { /* SEARCH_INDEX_FILES */ "files" , []() { return theTranslator->trFile(true,false); }, {} },
199 { /* SEARCH_INDEX_FUNCTIONS */ "functions" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
201 theTranslator->trFunctions(); }, {} },
202 { /* SEARCH_INDEX_VARIABLES */ "variables" , []() { return Config_getBool(OPTIMIZE_OUTPUT_SLICE) ?
204 theTranslator->trVariables(); }, {} },
205 { /* SEARCH_INDEX_TYPEDEFS */ "typedefs" , []() { return theTranslator->trTypedefs(); }, {} },
206 { /* SEARCH_INDEX_SEQUENCES */ "sequences" , []() { return theTranslator->trSequences(); }, {} },
207 { /* SEARCH_INDEX_DICTIONARIES */ "dictionaries", []() { return theTranslator->trDictionaries(); }, {} },
208 { /* SEARCH_INDEX_ENUMS */ "enums" , []() { return theTranslator->trEnumerations(); }, {} },
209 { /* SEARCH_INDEX_ENUMVALUES */ "enumvalues" , []() { return theTranslator->trEnumerationValues(); }, {} },
210 { /* SEARCH_INDEX_PROPERTIES */ "properties" , []() { return theTranslator->trProperties(); }, {} },
211 { /* SEARCH_INDEX_EVENTS */ "events" , []() { return theTranslator->trEvents(); }, {} },
212 { /* SEARCH_INDEX_RELATED */ "related" , []() { return theTranslator->trFriends(); }, {} },
213 { /* SEARCH_INDEX_DEFINES */ "defines" , []() { return theTranslator->trDefines(); }, {} },
214 { /* SEARCH_INDEX_GROUPS */ "groups" , []() { return theTranslator->trGroup(true,false); }, {} },
215 { /* SEARCH_INDEX_PAGES */ "pages" , []() { return theTranslator->trPage(true,false); }, {} },
216 { /* SEARCH_INDEX_CONCEPTS */ "concepts" , []() { return theTranslator->trConcept(true,false); }, {} },
217 { /* SEARCH_INDEX_MODULES */ "modules" , []() { return theTranslator->trModule(true,false); }, {} }
218} };
219
220static void addMemberToSearchIndex(const MemberDef *md)
221{
222 bool hideFriendCompounds = Config_getBool(HIDE_FRIEND_COMPOUNDS);
223 bool isLinkable = md->isLinkable();
224 const ClassDef *cd=nullptr;
225 const NamespaceDef *nd=nullptr;
226 const FileDef *fd=nullptr;
227 const GroupDef *gd=nullptr;
228 if (isLinkable &&
229 (
230 ((cd=md->getClassDef()) && cd->isLinkable() && !cd->isImplicitTemplateInstance()) ||
231 ((gd=md->getGroupDef()) && gd->isLinkable())
232 )
233 )
234 {
235 const DString &n = md->name();
236 if (!n.empty())
237 {
238 bool isFriendToHide = hideFriendCompounds && isTypeAClassFriend(md->typeString());
239 if (!(md->isFriend() && isFriendToHide))
240 {
242 }
243 if (md->isFunction() || md->isSlot() || md->isSignal())
244 {
246 }
247 else if (md->isVariable())
248 {
250 }
251 else if (md->isSequence())
252 {
254 }
255 else if (md->isDictionary())
256 {
258 }
259 else if (md->isTypedef())
260 {
262 }
263 else if (md->isEnumerate())
264 {
266 }
267 else if (md->isEnumValue())
268 {
270 }
271 else if (md->isProperty())
272 {
274 }
275 else if (md->isEvent())
276 {
278 }
279 else if (md->isRelated() || md->isForeign() ||
280 (md->isFriend() && !isFriendToHide))
281 {
283 }
284 }
285 }
286 else if (isLinkable &&
287 (((nd=md->getNamespaceDef()) && nd->isLinkable()) ||
288 ((fd=md->getFileDef()) && fd->isLinkable())
289 )
290 )
291 {
292 const DString &n = md->name();
293 if (!n.empty())
294 {
296
297 if (md->isFunction())
298 {
300 }
301 else if (md->isVariable())
302 {
304 }
305 else if (md->isSequence())
306 {
308 }
309 else if (md->isDictionary())
310 {
312 }
313 else if (md->isTypedef())
314 {
316 }
317 else if (md->isEnumerate())
318 {
320 }
321 else if (md->isEnumValue())
322 {
324 }
325 else if (md->isDefine())
326 {
328 }
329 }
330 }
331}
332
333//---------------------------------------------------------------------------------------------
334
336{
337 // index classes
338 for (const auto &cd : *Doxygen::classLinkedMap)
339 {
340 if (cd->isLinkable())
341 {
342 DString n = cd->localName();
344 if (Config_getBool(OPTIMIZE_OUTPUT_SLICE))
345 {
346 if (cd->compoundType()==ClassDef::Interface)
347 {
349 }
350 else if (cd->compoundType()==ClassDef::Struct)
351 {
353 }
354 else if (cd->compoundType()==ClassDef::Record)
355 {
357 }
358 else if (cd->compoundType()==ClassDef::Exception)
359 {
361 }
362 else // cd->compoundType()==ClassDef::Class
363 {
365 }
366 }
367 else // non slice optimization: group all types under classes
368 {
370 }
371 }
372 }
373
374 // index namespaces
375 for (const auto &nd : *Doxygen::namespaceLinkedMap)
376 {
377 if (nd->isLinkable())
378 {
379 DString n = nd->name();
382 }
383 }
384
385 // index concepts
386 for (const auto &cd : *Doxygen::conceptLinkedMap)
387 {
388 if (cd->isLinkable())
389 {
390 DString n = cd->localName();
393 }
394 }
395
396 // index modules
397 for (const auto &mod : ModuleManager::instance().modules())
398 {
399 if (mod->isLinkable() && mod->isPrimaryInterface())
400 {
401 DString n = mod->name();
404 }
405 }
406
407 // index files
408 for (const auto &fn : *Doxygen::inputNameLinkedMap)
409 {
410 for (const auto &fd : *fn)
411 {
412 DString n = fd->name();
413 if (fd->isLinkable())
414 {
417 }
418 }
419 }
420
421 // index class members
422 {
423 // for each member name
424 for (const auto &mn : *Doxygen::memberNameLinkedMap)
425 {
426 // for each member definition
427 for (const auto &md : *mn)
428 {
429 addMemberToSearchIndex(md.get());
430 }
431 }
432 }
433
434 // index file/namespace members
435 {
436 // for each member name
437 for (const auto &mn : *Doxygen::functionNameLinkedMap)
438 {
439 // for each member definition
440 for (const auto &md : *mn)
441 {
442 addMemberToSearchIndex(md.get());
443 }
444 }
445 }
446
447 // index groups
448 for (const auto &gd : *Doxygen::groupLinkedMap)
449 {
450 if (gd->isLinkable())
451 {
452 DString title(filterTitle(gd->groupTitle()).str());
453 SizeVector tokenIndices;
454 splitSearchTokens(title,tokenIndices);
455 for (size_t index : tokenIndices)
456 {
457 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),gd.get()));
458 g_searchIndexInfo[SEARCH_INDEX_GROUPS].add(SearchTerm(title.mid(index),gd.get()));
459 }
460 }
461 }
462
463 // index pages
464 for (const auto &pd : *Doxygen::pageLinkedMap)
465 {
466 if (pd->isLinkable())
467 {
468 DString title(filterTitle(pd->title()).str());
469 SizeVector tokenIndices;
470 splitSearchTokens(title,tokenIndices);
471 for (size_t index : tokenIndices)
472 {
473 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),pd.get()));
474 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),pd.get()));
475 }
476 }
477 }
478
479 // main page
481 {
482 DString title(filterTitle(Doxygen::mainPage->title()).str());
483 SizeVector tokenIndices;
484 splitSearchTokens(title,tokenIndices);
485 for (size_t index : tokenIndices)
486 {
489 }
490 }
491
492 // sections
493 const auto &sm = SectionManager::instance();
494 for (const auto &sectionInfo : sm)
495 {
496 if (sectionInfo->level()>0) // level 0 is for page titles
497 {
498 DString title = filterTitle(sectionInfo->title());
499 SizeVector tokenIndices;
500 splitSearchTokens(title,tokenIndices);
501 //printf("split(%s)=(%s) %zu\n",qPrint(sectionInfo->title()),qPrint(title),tokenIndices.size());
502 for (size_t index : tokenIndices)
503 {
504 g_searchIndexInfo[SEARCH_INDEX_ALL].add(SearchTerm(title.mid(index),sectionInfo.get()));
505 g_searchIndexInfo[SEARCH_INDEX_PAGES].add(SearchTerm(title.mid(index),sectionInfo.get()));
506 }
507 }
508 }
509
510 // sort all lists
511 for (auto &sii : g_searchIndexInfo) // for each index
512 {
513 for (auto &[name,symList] : sii.symbolMap) // for each symbol in the index
514 {
515 // sort the symbols (first on search term, and then on full name)
516 //
517 // `std::stable_sort` is used here due to reproducibility issues
518 // on key collisions
519 // https://github.com/doxygen/doxygen/issues/10445
520 std::stable_sort(symList.begin(),
521 symList.end(),
522 [](const auto &t1,const auto &t2)
523 {
524 int eq = dstricmp_sort(t1.word,t2.word); // search term first
525 return eq==0 ? dstricmp_sort(t1.title,t2.title)<0 : eq<0; // then full title
526 });
527 }
528 }
529}
530
531static void writeJavascriptSearchData(const DString &searchDirName)
532{
533 std::ofstream t = Portable::openOutputStream(searchDirName+"/searchdata.js");
534 if (t.is_open())
535 {
536 t << "var indexSectionsWithContent =\n";
537 t << "{\n";
538 int j=0;
539 for (const auto &sii : g_searchIndexInfo)
540 {
541 if (!sii.symbolMap.empty())
542 {
543 if (j>0) t << ",\n";
544 t << " " << j << ": \"";
545
546 std::string previous_letter; // start with value that does not exist in the map
547 for (const auto &[letter,list] : sii.symbolMap)
548 {
549 if (letter != previous_letter)
550 {
551 if ( letter == "\"" ) t << "\\"; // add escape for backslash
552 t << letter;
553 previous_letter = letter;
554 }
555 }
556 t << "\"";
557 j++;
558 }
559 }
560 if (j>0) t << "\n";
561 t << "};\n\n";
562 t << "var indexSectionNames =\n";
563 t << "{\n";
564 j=0;
565 for (const auto &sii : g_searchIndexInfo)
566 {
567 if (!sii.symbolMap.empty())
568 {
569 if (j>0) t << ",\n";
570 t << " " << j << ": \"" << convertToJSString(sii.name,true,false) << "\"";
571 j++;
572 }
573 }
574 if (j>0) t << "\n";
575 t << "};\n\n";
576 t << "var indexSectionLabels =\n";
577 t << "{\n";
578 j=0;
579 for (const auto &sii : g_searchIndexInfo)
580 {
581 if (!sii.symbolMap.empty())
582 {
583 if (j>0) t << ",\n";
584 t << " " << j << ": \"" << convertToJSString(convertToXML(sii.getText()),true,false) << "\"";
585 j++;
586 }
587 }
588 if (j>0) t << "\n";
589 t << "};\n\n";
590 }
591}
592
593static void writeJavasScriptSearchDataPage(const DString &baseName,const DString &dataFileName,const SearchIndexList &list)
594{
595 auto isDef = [](const SearchTerm::LinkInfo &info)
596 {
597 return std::holds_alternative<const Definition *>(info);
598 };
599 auto getDef = [&isDef](const SearchTerm::LinkInfo &info)
600 {
601 return isDef(info) ? std::get<const Definition *>(info) : nullptr;
602 };
603 auto isSection = [](const SearchTerm::LinkInfo &info)
604 {
605 return std::holds_alternative<const SectionInfo *>(info);
606 };
607 auto getSection = [&isSection](const SearchTerm::LinkInfo &info)
608 {
609 return isSection(info) ? std::get<const SectionInfo *>(info) : nullptr;
610 };
611
612 int cnt = 0;
613 std::ofstream ti = Portable::openOutputStream(dataFileName);
614 if (!ti.is_open())
615 {
616 err("Failed to open file '{}' for writing...\n",dataFileName);
617 return;
618 }
619
620 ti << "var searchData=\n";
621 // format
622 // searchData[] = array of items
623 // searchData[x][0] = id
624 // searchData[x][1] = [ name + child1 + child2 + .. ]
625 // searchData[x][1][0] = name as shown
626 // searchData[x][1][y+1] = info for child y
627 // searchData[x][1][y+1][0] = url
628 // searchData[x][1][y+1][1] = 1 => target="_parent"
629 // searchData[x][1][y+1][1] = 0 => target="_blank"
630 // searchData[x][1][y+1][2] = scope
631
632 ti << "[\n";
633 bool firstEntry=true;
634
635 int childCount=0;
636 DString lastWord;
637 const Definition *prevScope = nullptr;
638 for (auto it = list.begin(); it!=list.end();)
639 {
640 const SearchTerm &term = *it;
641 const SearchTerm::LinkInfo info = term.info;
642 const Definition *d = getDef(info);
643 const SectionInfo *si = getSection(info);
644 ASSERT(d || si); // either d or si should be valid
645 DString word = term.word;
646 DString id = term.termEncoded();
647 ++it;
648 const Definition *scope = d ? d->getOuterScope() : nullptr;
649 const SearchTerm::LinkInfo next = it!=list.end() ? it->info : SearchTerm::LinkInfo();
650 const Definition *nextScope = isDef(next) ? getDef(next)->getOuterScope() : nullptr;
651 const MemberDef *md = toMemberDef(d);
652 DString anchor = d ? d->anchor() : si ? si->label() : DString();
653
654 if (word!=lastWord) // this item has a different search word
655 {
656 if (!firstEntry)
657 {
658 ti << "]]]";
659 ti << ",\n";
660 }
661 firstEntry=false;
662 ti << " ['" << id << "_" << cnt++ << "',['";
663 if (next==SearchTerm::LinkInfo() || it->word!=word) // unique result, show title
664 {
665 ti << convertToJSString(convertToXML(term.title),true,true);
666 }
667 else // multiple results, show matching word only, expanded list will show title
668 {
669 ti << convertToJSString(convertToXML(term.word),true,true);
670 }
671 ti << "',[";
672 childCount=0;
673 prevScope=nullptr;
674 }
675
676 if (childCount>0)
677 {
678 ti << "],[";
679 }
680 DString fn = d ? d->getOutputFileBase() : si ? si->fileName() : DString();
681 DString ref = d ? d->getReference() : si ? si->ref() : DString();
683 DString extRef = externalRef("../",ref)+fn;
684 if (!anchor.empty())
685 {
686 extRef+="#"+anchor;
687 }
688 ti << "'" << convertToJSString(extRef,true,true) << "',";
689
690 bool extLinksInWindow = Config_getBool(EXT_LINKS_IN_WINDOW);
691 if (!extLinksInWindow || ref.empty())
692 {
693 ti << "1,";
694 }
695 else
696 {
697 ti << "0,";
698 }
699
700 if (lastWord!=word && (next==SearchTerm::LinkInfo() || it->word!=word)) // unique search result
701 {
702 if (d && d->getOuterScope()!=Doxygen::globalScope)
703 {
704 ti << "'" << convertToJSString(convertToXML(d->getOuterScope()->name()),true,true) << "'";
705 }
706 else if (md)
707 {
708 const FileDef *fd = md->getBodyDef();
709 if (fd==nullptr) fd = md->getFileDef();
710 if (fd)
711 {
712 ti << "'" << convertToJSString(convertToXML(fd->localName()),true,true) << "'";
713 }
714 }
715 else
716 {
717 ti << "''";
718 }
719 }
720 else // multiple entries with the same name
721 {
722 bool found=false;
723 bool overloadedFunction = ((prevScope!=nullptr && scope==prevScope) || (scope && scope==nextScope)) &&
724 md && md->isCallable();
726 if (md) prefix=convertToXML(md->localName());
727 if (overloadedFunction) // overloaded member function
728 {
730 // show argument list to disambiguate overloaded functions
731 }
732 else if (md && md->isCallable()) // unique member function
733 {
734 prefix+="()"; // only to show it is a callable symbol
735 }
736 DString name;
737 if (d)
738 {
739 switch (d->definitionType())
740 {
741 case Definition::TypeClass: name = convertToXML((toClassDef(d))->displayName()); found=true; break;
742 case Definition::TypeNamespace: name = convertToXML((toNamespaceDef(d))->displayName()); found=true; break;
743 case Definition::TypeModule: name = convertToXML(d->name()+" "+theTranslator->trModule(false,true)); found=true; break;
744 case Definition::TypePage: name = convertToXML(filterTitle(toPageDef(d)->title())); found=true; break;
745 case Definition::TypeGroup: name = convertToXML(filterTitle(toGroupDef(d)->groupTitle())); found=true; break;
746 default:
747 if (scope==nullptr || scope==Doxygen::globalScope) // in global scope
748 {
749 if (md)
750 {
751 const FileDef *fd = md->getBodyDef();
752 if (fd==nullptr) fd = md->resolveAlias()->getFileDef();
753 if (fd)
754 {
755 if (!prefix.empty()) prefix+=":&#160;";
756 name = prefix + convertToXML(fd->localName());
757 found = true;
758 }
759 }
760 }
761 else if (md && (md->resolveAlias()->getClassDef() || md->resolveAlias()->getNamespaceDef()))
762 // member in class or namespace scope
763 {
764 SrcLangExt lang = md->getLanguage();
766 name = convertToXML(d->getOuterScope()->qualifiedName()) + sep + prefix;
767 found = true;
768 }
769 else if (scope) // some thing else? -> show scope
770 {
771 name = prefix + convertToXML(scope->name());
772 found = true;
773 }
774 break;
775 }
776 }
777 else if (si)
778 {
779 name = parseCommentAsHtml(si->definition(),nullptr,si->title(),si->fileName(),si->lineNr());
780 name = convertToXML(name);
781 found = true;
782 }
783 if (!found) // fallback
784 {
785 name = prefix + "("+theTranslator->trGlobalNamespace()+")";
786 }
787
788 ti << "'" << convertToJSString(name,true,true) << "'";
789
790 prevScope = scope;
791 childCount++;
792 }
793 lastWord = word;
794 }
795 if (!firstEntry)
796 {
797 ti << "]]]\n";
798 }
799 ti << "];\n";
800 Doxygen::indexList->addStyleSheetFile(("search/"+baseName+".js").data());
801}
802
803
805{
806 // write index files
807 DString searchDirName = Config_getString(HTML_OUTPUT)+"/search";
808
809 std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
810 if (numThreads>1) // multi threaded version
811 {
812 ThreadPool threadPool(numThreads);
813 std::vector< std::future<int> > results;
814 for (auto &sii : g_searchIndexInfo)
815 {
816 int p=0;
817 for (const auto &[letter,symList] : sii.symbolMap)
818 {
819 DString baseName;
820 baseName.sprintf("%s_%x",sii.name.data(),p);
821 DString dataFileName = searchDirName + "/"+baseName+".js";
822 auto &list = symList;
823 auto processFile = [p,baseName,dataFileName,&list]()
824 {
825 writeJavasScriptSearchDataPage(baseName,dataFileName,list);
826 return p;
827 };
828 results.emplace_back(threadPool.queue(processFile));
829 p++;
830 }
831 }
832 // wait for the results
833 for (auto &f : results) f.get();
834 }
835 else // single threaded version
836 {
837 for (auto &sii : g_searchIndexInfo)
838 {
839 int p=0;
840 for (const auto &[letter,symList] : sii.symbolMap)
841 {
842 DString baseName;
843 baseName.sprintf("%s_%x",sii.name.data(),p);
844 DString dataFileName = searchDirName + "/"+baseName+".js";
845 writeJavasScriptSearchDataPage(baseName,dataFileName,symList);
846 p++;
847 }
848 }
849 }
850
851 writeJavascriptSearchData(searchDirName);
852 auto &mgr = ResourceMgr::instance();
853 {
854 std::ofstream fn = Portable::openOutputStream(searchDirName+"/search.js");
855 if (fn.is_open())
856 {
857 TextStream t(&fn);
858 t << substitute(mgr.getAsString("search.js"),"$PROJECTID",getProjectId());
859 }
860 }
861
862 Doxygen::indexList->addStyleSheetFile("search/searchdata.js");
863 Doxygen::indexList->addStyleSheetFile("search/search.js");
864}
865
866//--------------------------------------------------------------------------------------
867
869{
870 std::string letter = convertUTF8ToLower(getUTF8CharAt(term.word.str(),0));
871 auto &list = symbolMap[letter]; // creates a new entry if not found
872 list.push_back(term);
873}
874
875const std::array<SearchIndexInfo,NUM_SEARCH_INDICES> &getSearchIndices()
876{
877 return g_searchIndexInfo;
878}
879
constexpr auto prefix
Definition anchor.cpp:47
A abstract class representing of a compound symbol.
Definition classdef.h:100
virtual bool isImplicitTemplateInstance() const =0
@ Interface
Definition classdef.h:109
@ Exception
Definition classdef.h:112
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
void resize(size_t newlen)
Definition dstring.h:209
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
const std::string & str() const
Definition dstring.h:645
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual DString getDefFileName() const =0
virtual bool isLinkable() const =0
virtual int getDefLine() const =0
virtual DefType definitionType() const =0
virtual const DString & name() const =0
virtual const DString & localName() const =0
virtual const FileDef * getBodyDef() 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
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static ConceptLinkedMap * conceptLinkedMap
Definition doxygen.h:90
static std::unique_ptr< PageDef > mainPage
Definition doxygen.h:93
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:88
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
static IndexList * indexList
Definition doxygen.h:125
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:92
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
static GroupLinkedMap * groupLinkedMap
Definition doxygen.h:107
A model of a file symbol.
Definition filedef.h:97
A model of a group of symbols.
Definition groupdef.h:48
void addStyleSheetFile(const DString &name)
Definition indexlist.h:127
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual bool isSignal() const =0
virtual bool isFriend() const =0
virtual DString argsString() const =0
virtual bool isForeign() const =0
virtual bool isRelated() const =0
virtual bool isSequence() const =0
virtual const ClassDef * getClassDef() const =0
virtual GroupDef * getGroupDef()=0
virtual bool isTypedef() const =0
virtual bool isSlot() const =0
virtual const FileDef * getFileDef() const =0
virtual bool isEvent() const =0
virtual bool isFunction() const =0
virtual bool isDictionary() const =0
virtual MemberDef * resolveAlias()=0
virtual bool isDefine() const =0
virtual const NamespaceDef * getNamespaceDef() const =0
virtual bool isEnumerate() const =0
virtual bool isVariable() const =0
virtual DString typeString() const =0
virtual bool isCallable() const =0
virtual bool isEnumValue() const =0
virtual bool isProperty() const =0
static ModuleManager & instance()
An abstract interface of a namespace symbol.
static ResourceMgr & instance()
Returns the one and only instance of this class.
class that provide information about a section.
Definition section.h:58
DString fileName() const
Definition section.h:74
Definition * definition() const
Definition section.h:77
int lineNr() const
Definition section.h:73
DString title() const
Definition section.h:70
DString ref() const
Definition section.h:72
DString label() const
Definition section.h:69
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
Text streaming class that buffers data.
Definition textstream.h:36
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:232
Class managing a pool of worker threads.
Definition threadpool.h:48
auto queue(F &&f, Args &&... args) -> std::future< decltype(f(args...))>
Queue the callable function f for the threads to execute.
Definition threadpool.h:77
virtual DString trTypedefs()=0
virtual DString trExceptions()=0
virtual DString trEnumerations()=0
virtual DString trClasses()=0
virtual DString trGroup(bool first_capital, bool singular)=0
virtual DString trNamespace(bool first_capital, bool singular)=0
virtual DString trStructs()=0
virtual DString trSequences()=0
virtual DString trFunctions()=0
virtual DString trFriends()=0
virtual DString trOperations()=0
virtual DString trGlobalNamespace()=0
virtual DString trModules()=0
virtual DString trDefines()=0
virtual DString trModule(bool first_capital, bool singular)=0
virtual DString trProperties()=0
virtual DString trConcept(bool first_capital, bool singular)=0
virtual DString trSliceInterfaces()=0
virtual DString trAll()=0
virtual DString trVariables()=0
virtual DString trEnumerationValues()=0
virtual DString trPage(bool first_capital, bool singular)=0
virtual DString trFile(bool first_capital, bool singular)=0
virtual DString trConstants()=0
virtual DString trEvents()=0
virtual DString trDictionaries()=0
virtual DString trRecords()=0
ClassDef * toClassDef(Definition *d)
#define Config_getInt(name)
Definition config.h:34
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
std::vector< size_t > SizeVector
Definition containers.h:39
DString parseCommentAsHtml(const Definition *scope, const MemberDef *member, const DString &doc, const DString &fileName, int lineNr)
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
GroupDef * toGroupDef(Definition *d)
Translator * theTranslator
Definition language.cpp:76
MemberDef * toMemberDef(Definition *d)
#define err(fmt,...)
Definition message.h:127
#define ASSERT(x)
Definition message.h:142
#define term(fmt,...)
Definition message.h:137
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:679
NamespaceDef * toNamespaceDef(Definition *d)
PageDef * toPageDef(Definition *d)
Definition pagedef.cpp:656
Portable versions of functions that are platform dependent.
static void addMemberToSearchIndex(const MemberDef *md)
#define SEARCH_INDEX_TYPEDEFS
#define SEARCH_INDEX_STRUCTS
static void writeJavascriptSearchData(const DString &searchDirName)
#define SEARCH_INDEX_NAMESPACES
void createJavaScriptSearchIndex()
#define SEARCH_INDEX_CONCEPTS
#define SEARCH_INDEX_EVENTS
static std::array< SearchIndexInfo, NUM_SEARCH_INDICES > g_searchIndexInfo
#define SEARCH_INDEX_DEFINES
#define SEARCH_INDEX_ENUMS
#define SEARCH_INDEX_FILES
#define SEARCH_INDEX_DICTIONARIES
#define SEARCH_INDEX_PAGES
#define SEARCH_INDEX_RECORDS
#define SEARCH_INDEX_ALL
#define SEARCH_INDEX_GROUPS
#define SEARCH_INDEX_INTERFACES
static void writeJavasScriptSearchDataPage(const DString &baseName, const DString &dataFileName, const SearchIndexList &list)
const std::array< SearchIndexInfo, NUM_SEARCH_INDICES > & getSearchIndices()
#define SEARCH_INDEX_SEQUENCES
#define SEARCH_INDEX_PROPERTIES
#define SEARCH_INDEX_ENUMVALUES
static void splitSearchTokens(DString &title, SizeVector &indices)
#define SEARCH_INDEX_FUNCTIONS
#define SEARCH_INDEX_VARIABLES
#define SEARCH_INDEX_MODULES
#define SEARCH_INDEX_CLASSES
#define SEARCH_INDEX_RELATED
void writeJavaScriptSearchIndex()
#define SEARCH_INDEX_EXCEPTIONS
Javascript based search engine.
std::vector< SearchTerm > SearchIndexList
List of search terms.
void add(const SearchTerm &term)
SearchIndexMap symbolMap
Searchable term.
DString word
lower case word that is indexed (e.g. name of a symbol, or word from a title)
std::variant< std::monostate, const Definition *, const SectionInfo * > LinkInfo
LinkInfo info
definition to link to
DString title
title to show in the output for this search result
DString termEncoded() const
encoded version of the search term
bool isTypeAClassFriend(const DString &type)
Definition types.h:924
SrcLangExt
Definition types.h:207
std::string convertUTF8ToLower(const std::string &input)
Converts the input string into a lower case version, also taking into account non-ASCII characters th...
Definition utf8.cpp:191
std::string getUTF8CharAt(const std::string &input, size_t pos)
Returns the UTF8 character found at byte position pos in the input string.
Definition utf8.cpp:131
DString filterTitle(const DString &title)
Definition util.cpp:4590
DString getProjectId()
Definition util.cpp:5427
DString convertToJSString(const DString &s, bool keepEntities, bool singleQuotes)
Definition util.cpp:3483
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:4063
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3364
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4765
DString externalRef(const DString &relPath, const DString &ref)
Definition util.cpp:4674
A bunch of utility functions.