Doxygen
Loading...
Searching...
No Matches
util.h File Reference

A bunch of utility functions. More...

#include <src/util.h>

Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ReadInputFileOptions
struct  GetDefInput
struct  GetDefResult
struct  SelectionBlock
struct  SelectionMarkerInfo
struct  KeywordSubstitution

Typedefs

using SelectionBlockList = std::vector<SelectionBlock>
using KeywordSubstitutionList = std::vector<KeywordSubstitution>

Functions

DString getLanguageSpecificSeparator (SrcLangExt lang, bool classScope=false)
DString fileToString (const DString &name, bool filter=false, bool isSourceCode=false)
bool readInputFile (const DString &fileName, std::string &contents, const ReadInputFileOptions &options=ReadInputFileOptions())
 read a file name fileName and optionally filter and transcode it
DString writeInlineGraph (const DString &baseName, const DString &extension, const DString &content, bool &exists)
void cleanupInlineGraphs ()
GetDefResult getDefs (const GetDefInput &input)
DString getFileFilter (const DString &name, bool isSourceCode)
bool resolveRef (const DString &scName, const DString &name, bool inSeeBlock, const Definition **resContext, const MemberDef **resMember, SrcLangExt lang, bool lookForSpecializations=true, const FileDef *currentFile=nullptr, bool checkScope=false)
bool resolveLink (const DString &scName, const DString &lr, bool inSeeBlock, const Definition **resContext, DString &resAnchor, SrcLangExt lang, const DString &prefix=DString(), const FileDef *currentFile=nullptr)
DString resolveTypeDef (const Definition *d, const DString &name, const Definition **typedefContext=nullptr)
DString externalRef (const DString &relPath, const DString &ref)
bool matchArguments2 (const Definition *srcScope, const FileDef *srcFileScope, const DString &srcReturnType, const ArgumentList *srcAl, const Definition *dstScope, const FileDef *dstFileScope, const DString &dstReturnType, const ArgumentList *dstAl, bool checkCV, SrcLangExt lang)
void mergeArguments (ArgumentList &srcAl, ArgumentList &dstAl, bool forceNameOverwrite=false)
bool matchTemplateArguments (const ArgumentList &srcAl, const ArgumentList &dstAl)
DString normalizeNonTemplateArgumentsInString (const DString &name, const Definition *context, const ArgumentList &formalArgs)
DString substituteTemplateArgumentsInString (const DString &name, const ArgumentList &formalArgs, const ArgumentList *actualArgs)
DString inlineArgListToDoc (const ArgumentList &al)
DString inlineTemplateArgListToDoc (const ArgumentList &al)
DString argListToString (const ArgumentList &al, bool useCanonicalType=false, bool showDefVals=true)
DString tempArgListToString (const ArgumentList &al, SrcLangExt lang, bool includeDefaults=true)
DString selectBlocks (const DString &s, const SelectionBlockList &blockList, const SelectionMarkerInfo &markerInfo)
 remove disabled blocks and all block markers from s and return the result as a string
void checkBlocks (const DString &s, const DString fileName, const SelectionMarkerInfo &markerInfo)
DString findExampleFilePath (const DString &file, bool &ambig)
void writeExamples (OutputList &ol, const ExampleList &el)
DString stripScope (const DString &name)
DString stripAnonymousNamespaceScope (const DString &s)
DString stripFromPath (const DString &path)
DString stripFromIncludePath (const DString &path)
DString stripPath (const DString &s)
DString stripIndentation (const DString &s, bool skipFirstLine=false)
DString stripExtensionGeneral (const DString &fName, const DString &ext)
DString stripExtension (const DString &fName)
DString stripLeadingAndTrailingEmptyLines (const DString &s, int &docLine)
 Special version of DString::stripWhiteSpace() that only strips completely blank lines.
void stripIndentationVerbatim (DString &doc, size_t indentationLevel, bool skipFirstLine=true)
DString removeRedundantWhiteSpace (const DString &s)
DString detab (const DString &s, size_t &refIndent)
bool rightScopeMatch (const DString &scope, const DString &name)
bool leftScopeMatch (const DString &scope, const DString &name)
DString substituteKeywords (const DString &file, const DString &s, const KeywordSubstitutionList &keywords)
void addDirPrefix (DString &fileName)
int getPrefixIndex (const DString &name)
int computeQualifiedIndex (const DString &name)
 Return the index of the last :: in the string name that is still before the first <.
DString convertNameToFile (const DString &name, bool allowDots=false, bool allowUnderscore=false)
DString escapeCharsInString (const DString &name, bool allowDots, bool allowUnderscore=false)
DString unescapeCharsInString (const DString &s)
DString linkToText (SrcLangExt lang, const DString &link, bool ignoreDots)
DString removeAnonymousScopes (const DString &s)
DString replaceAnonymousScopes (const DString &s, const DString &replacement=DString())
DString insertTemplateSpecifierInScope (const DString &scope, const DString &templ)
DString stripTemplateSpecifiersFromScope (const DString &fullName, bool parentOnly=true, DString *lastScopeStripped=nullptr, DString scopeName=DString(), bool allowArtificial=true)
DString mergeScopes (const DString &leftScope, const DString &rightScope)
int getScopeFragment (const DString &s, int p, int *l)
DString convertToId (const DString &s)
DString convertToHtml (const DString &s, bool keepEntities=true)
DString convertToXML (const DString &s, bool keepEntities=false, bool citeEntry=false)
DString convertToJSString (const DString &s, bool keepEntities=false, bool singleQuotes=false)
bool updateLanguageMapping (const DString &extension, const DString &parser)
SrcLangExt getLanguageFromFileName (const DString &fileName, SrcLangExt defLang=SrcLangExt::Cpp)
SrcLangExt getLanguageFromCodeLang (DString &fileName)
 Routine to handle the language attribute of the \code command.
DString getFileNameExtension (const DString &fn)
void initDefaultExtensionMapping ()
void addCodeOnlyMappings ()
void writeMarkerList (OutputList &ol, const std::string &markerText, size_t numMarkers, std::function< void(size_t)> replaceFunc)
DString writeMarkerList (const std::string &markerText, size_t numMarkers, std::function< DString(size_t)> replaceFunc)
DString replaceColorMarkers (const DString &str)
 Replaces any markers of the form ##AA in input string str by new markers of the form #AABBCC, where #AABBCC represents a valid color, based on the intensity represented by hex number AA and the current HTML_COLORSTYLE_* settings.
void createSubDirs (const Dir &d)
void clearSubDirs (const Dir &d)
DString relativePathToRoot (const DString &name)
bool copyFile (const DString &src, const DString &dest)
 Copies the contents of file with name src to the newly created file with name dest.
bool openOutputFile (const DString &outFile, std::ofstream &f)
bool isURL (const DString &url)
 Checks whether the given url starts with a supported protocol.
DString correctURL (const DString &url, const DString &relPath)
 Corrects URL url according to the relative path relPath.
DString createHtmlUrl (const DString &relPath, const DString &ref, bool islocalFile, const DString &targetFileName, const DString &anchor)
DString mangleCSharpGenericName (const DString &name)
DString demangleCSharpGenericName (const DString &name, const DString &templArgs)
DString extractBeginRawStringDelimiter (const char *rawStart)
DString extractEndRawStringDelimiter (const char *rawEnd)
void extractNamespaceName (const DString &scopeName, DString &className, DString &namespaceName, bool allowEmptyClass=false)
int extractClassNameFromType (const DString &type, int &pos, DString &name, DString &templSpec, SrcLangExt=SrcLangExt::Unknown)
bool useCaseSenseNames ()
 Returns true if the names of the symbols can be case sensitive.
bool checkExtension (const DString &fName, const DString &ext)
void addHtmlExtensionIfMissing (DString &fName)
bool checkIfTypedef (const Definition *scope, const FileDef *fileScope, const DString &n)
void addGroupListToTitle (OutputList &ol, const Definition *d)
void writeTypeConstraints (OutputList &ol, const Definition *d, const ArgumentList &al)
void stackTrace ()
bool protectionLevelVisible (Protection prot)
void convertProtectionLevel (MemberListType inListType, Protection inProt, MemberListType *outListType1, MemberListType *outListType2)
 Computes for a given list type inListType, which are the the corresponding list type(s) in the base class that are to be added to this list.
DString makeBaseName (const DString &name, const DString &ext)
DString determineAbsoluteIncludeName (const DString &curFile, const DString &incFileName)
DString filterTitle (const DString &title)
DString getDotImageExtension ()
DString getDotImageExtension (const DString &format)
DString getDotImageExtensionGenerated (const DString &format)
DString externalLinkTarget (const bool parent=false)
DString getEncoding (const FileInfo &fi)
bool mainPageHasTitle ()
DString getProjectId ()
DString projectLogoFile ()
DString projectLogoSize ()
DString showDate (const DString &fmt)

Detailed Description

A bunch of utility functions.

Definition in file util.h.

Typedef Documentation

◆ KeywordSubstitutionList

Definition at line 283 of file util.h.

◆ SelectionBlockList

using SelectionBlockList = std::vector<SelectionBlock>

Definition at line 231 of file util.h.

Function Documentation

◆ addCodeOnlyMappings()

void addCodeOnlyMappings ( )

Definition at line 4171 of file util.cpp.

4172{
4173 updateLanguageMapping(".xml", "xml");
4174 updateLanguageMapping(".sql", "sql");
4175}
bool updateLanguageMapping(const DString &extension, const DString &language)
Definition util.cpp:4072

References updateLanguageMapping().

Referenced by generateOutput().

◆ addDirPrefix()

void addDirPrefix ( DString & fileName)

References parent().

◆ addGroupListToTitle()

void addGroupListToTitle ( OutputList & ol,
const Definition * d )

◆ addHtmlExtensionIfMissing()

void addHtmlExtensionIfMissing ( DString & fName)

Definition at line 3940 of file util.cpp.

3941{
3942 if (fName.empty()) return;
3943 size_t i_fs = fName.rfind('/');
3944 size_t i_bs = fName.rfind('\\');
3945 size_t p = i_fs!=DString::npos && i_bs!=DString::npos ? std::max(i_fs, i_bs) :
3946 i_fs!=DString::npos ? i_fs : i_bs!=DString::npos ? i_bs : 0;
3947 size_t i = fName.find('.',p); // search for . after path part
3948 if (i==DString::npos)
3949 {
3951 }
3952}
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
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
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
static DString htmlFileExtension
Definition doxygen.h:115

References DString::empty(), DString::find(), Doxygen::htmlFileExtension, DString::npos, and DString::rfind().

Referenced by HtmlCodeGenerator::_writeCodeLink(), Crawlmap::addContentsItem(), DocSets::addContentsItem(), EclipseHelp::addContentsItem(), HtmlHelp::addContentsItem(), Qhp::addContentsItem(), Crawlmap::addIndexFile(), Sitemap::addIndexFile(), common_attributes(), convertMapFile(), dumpSymbol(), field2URL(), FTVHelp::Private::generateTree(), Crawlmap::initialize(), makeFileName(), makeFileName(), makeURL(), DefinitionImpl::navigationPathAsString(), node2URL(), HtmlDocVisitor::operator()(), replaceRef(), SearchIndexExternal::setCurrentDoc(), HtmlGenerator::startFile(), HtmlGenerator::startIndexItem(), HtmlDocVisitor::startLink(), HtmlGenerator::startTextLink(), LayoutNavEntry::url(), DefinitionImpl::writeDocAnchorsToTagFile(), HtmlGenerator::writeInheritedSectionTitle(), writeJavasScriptSearchDataPage(), writeMapArea(), HtmlGenerator::writeObjectLink(), ClassDefImpl::writeQuickMemberLinks(), FileDefImpl::writeQuickMemberLinks(), GroupDefImpl::writeQuickMemberLinks(), NamespaceDefImpl::writeQuickMemberLinks(), HtmlGenerator::writeSplitBarAsString(), HtmlGenerator::writeStartAnnoItem(), HtmlGenerator::writeSummaryLink(), ClassDefImpl::writeTagFile(), ConceptDefImpl::writeTagFile(), DirDefImpl::writeTagFile(), FileDefImpl::writeTagFile(), GroupDefImpl::writeTagFile(), MemberDefImpl::writeTagFile(), ModuleDefImpl::writeTagFile(), NamespaceDefImpl::writeTagFile(), PageDefImpl::writeTagFile(), RequirementManager::writeTagFile(), VhdlDocGen::writeTagFile(), DocSets::writeToken(), HtmlCodeGenerator::writeTooltip(), and DotNode::writeUrl().

◆ argListToString()

DString argListToString ( const ArgumentList & al,
bool useCanonicalType = false,
bool showDefVals = true )

Returns a string representation of the parameter list al. If useCanonicalType is true then the canonical type is used for each argument. If showDefVals is true then default values are included in the string representation.

Definition at line 864 of file util.cpp.

865{
866 DString result;
867 if (!al.hasParameters()) return result;
868 result+="(";
869 for (auto it = al.begin() ; it!=al.end() ;)
870 {
871 Argument a = *it;
872 DString type1 = useCanonicalType && !a.canType.empty() ? a.canType : a.type;
873 DString type2;
874 if (size_t i=type1.find(")("); i!=DString::npos) // hack to deal with function pointers
875 {
876 type2=type1.mid(i);
877 type1=type1.left(i);
878 }
879 if (!a.attrib.empty())
880 {
881 result+=a.attrib+" ";
882 }
883 if (!a.name.empty() || !a.array.empty())
884 {
885 result+= type1+" "+a.name+type2+a.array;
886 }
887 else
888 {
889 result+= type1+type2;
890 }
891 if (!a.defval.empty() && showDefVals)
892 {
893 result+="="+a.defval;
894 }
895 ++it;
896 if (it!=al.end()) result+=", ";
897 }
898 result+=")";
899 if (al.constSpecifier()) result+=" const";
900 if (al.volatileSpecifier()) result+=" volatile";
901 if (al.refQualifier()==RefQualifierType::LValue) result+=" &";
902 else if (al.refQualifier()==RefQualifierType::RValue) result+=" &&";
903 if (!al.trailingReturnType().empty()) result+=al.trailingReturnType();
904 if (al.pureSpecifier()) result+=" =0";
905 return removeRedundantWhiteSpace(result);
906}
This class contains the information about the argument of a function or template.
Definition arguments.h:27
DString attrib
Definition arguments.h:42
DString defval
Definition arguments.h:47
DString array
Definition arguments.h:46
DString name
Definition arguments.h:45
DString type
Definition arguments.h:43
DString canType
Definition arguments.h:44
RefQualifierType refQualifier() const
Definition arguments.h:117
bool pureSpecifier() const
Definition arguments.h:114
iterator end()
Definition arguments.h:95
bool hasParameters() const
Definition arguments.h:77
DString trailingReturnType() const
Definition arguments.h:115
bool constSpecifier() const
Definition arguments.h:112
iterator begin()
Definition arguments.h:94
bool volatileSpecifier() const
Definition arguments.h:113
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
DString left(size_t len) const
Definition dstring.h:306
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427

References Argument::array, Argument::attrib, ArgumentList::begin(), Argument::canType, ArgumentList::constSpecifier(), Argument::defval, DString::empty(), ArgumentList::end(), DString::find(), ArgumentList::hasParameters(), DString::left(), LValue, DString::mid(), Argument::name, DString::npos, ArgumentList::pureSpecifier(), ArgumentList::refQualifier(), removeRedundantWhiteSpace(), RValue, ArgumentList::trailingReturnType(), Argument::type, and ArgumentList::volatileSpecifier().

Referenced by addMemberFunction(), DocParser::checkArgumentName(), DocParser::checkUnOrMultipleDocumentedParams(), findFriends(), findGlobalMember(), findMember(), SymbolResolver::Private::getResolvedSymbol(), matchArguments2(), matchTemplateArguments(), mergeArguments(), substituteTemplateArgumentsInString(), and ClassDefImpl::title().

◆ checkBlocks()

void checkBlocks ( const DString & s,
const DString fileName,
const SelectionMarkerInfo & markerInfo )

Definition at line 5142 of file util.cpp.

5143{
5144 if (s.empty()) return;
5145
5146 const char *p = s.data();
5147 char c = 0;
5148 while ((c=*p))
5149 {
5150 if (c==markerInfo.markerChar) // potential start of marker
5151 {
5152 if (dstrncmp(p,markerInfo.beginStr,markerInfo.beginLen)==0) // start of begin marker
5153 {
5154 size_t len = markerInfo.beginLen;
5155 bool negate = *(p+len)=='!';
5156 if (negate) len++;
5157 p += len;
5158 DString marker;
5159 while (*p)
5160 {
5161 if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
5162 {
5163 warn(fileName,-1,"Remaining begin replacement with marker '{}'",marker);
5164 break;
5165 }
5166 else if (markerInfo.closeLen!= 0 && dstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5167 {
5168 p += markerInfo.closeLen;
5169 warn(fileName,-1,"Remaining begin replacement with marker '{}'",marker);
5170 break;
5171 }
5172 marker += *p;
5173 p++;
5174 }
5175 }
5176 else if (dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // start of end marker
5177 {
5178 size_t len = markerInfo.endLen;
5179 bool negate = *(p+len)=='!';
5180 if (negate) len++;
5181 p += len;
5182 DString marker;
5183 while (*p)
5184 {
5185 if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
5186 {
5187 warn(fileName,-1,"Remaining end replacement with marker '{}'",marker);
5188 break;
5189 }
5190 else if (markerInfo.closeLen!= 0 && dstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5191 {
5192 p += markerInfo.closeLen;
5193 warn(fileName,-1,"Remaining end replacement with marker '{}'",marker);
5194 break;
5195 }
5196 marker += *p;
5197 p++;
5198 }
5199 }
5200 }
5201 p++;
5202 }
5203}
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
int dstrncmp(const char *str1, const char *str2, size_t len)
Definition dstring.h:56
#define warn(file, line, fmt,...)
Definition message.h:97
size_t beginLen
Definition util.h:237
const char * closeStr
Definition util.h:240
const char * beginStr
Definition util.h:236
size_t closeLen
Definition util.h:241
const char * endStr
Definition util.h:238

References SelectionMarkerInfo::beginLen, SelectionMarkerInfo::beginStr, SelectionMarkerInfo::closeLen, SelectionMarkerInfo::closeStr, DString::data(), dstrncmp(), DString::empty(), SelectionMarkerInfo::endLen, SelectionMarkerInfo::endStr, SelectionMarkerInfo::markerChar, and warn.

Referenced by HtmlGenerator::init(), and LatexGenerator::init().

◆ checkExtension()

bool checkExtension ( const DString & fName,
const DString & ext )

Definition at line 3935 of file util.cpp.

3936{
3937 return fName.right(ext.length())==ext;
3938}
DString right(size_t len) const
Definition dstring.h:311
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151

References DString::length(), and DString::right().

Referenced by copyLatexStyleSheet(), and extraLatexStyleSheet().

◆ checkIfTypedef()

bool checkIfTypedef ( const Definition * scope,
const FileDef * fileScope,
const DString & n )

Returns true iff the given name string appears to be a typedef in scope.

Definition at line 4280 of file util.cpp.

4281{
4282 MemberDef *bestMatch = getMemberFromSymbol(scope,fileScope,n);
4283
4284 if (bestMatch && bestMatch->isTypedef())
4285 return true; // closest matching symbol is a typedef
4286 else
4287 return false;
4288}
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual bool isTypedef() const =0
static MemberDef * getMemberFromSymbol(const Definition *scope, const FileDef *fileScope, const DString &n)
Definition util.cpp:4228

References getMemberFromSymbol(), and MemberDef::isTypedef().

Referenced by isVarWithConstructor().

◆ cleanupInlineGraphs()

void cleanupInlineGraphs ( )

Deletes all graph files written with writeInlineGraph()

Definition at line 5435 of file util.cpp.

5436{
5437 if (Config_getBool(DOT_CLEANUP))
5438 {
5439 for (const auto& fileName: writeFileContents_set)
5440 {
5441 Dir().remove(qPrint(fileName));
5442 }
5443 }
5444}
Class representing a directory in the file system.
Definition dir.h:73
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:319
#define Config_getBool(name)
Definition config.h:33
const char * qPrint(const char *s)
Definition dstring.h:783
static StringUnorderedSet writeFileContents_set
Definition util.cpp:5408

References Config_getBool, qPrint(), Dir::remove(), and writeFileContents_set.

Referenced by generateOutput().

◆ clearSubDirs()

void clearSubDirs ( const Dir & d)

Definition at line 3005 of file util.cpp.

3006{
3007 if (Config_getBool(CREATE_SUBDIRS))
3008 {
3009 // remove empty subdirectories
3010 int createSubdirsLevelPow2 = 1 << Config_getInt(CREATE_SUBDIRS_LEVEL);
3011 for (int l1=0;l1<16;l1++)
3012 {
3013 DString subdir;
3014 subdir.sprintf("d%x",l1);
3015 for (int l2=0; l2 < createSubdirsLevelPow2; l2++)
3016 {
3017 DString subsubdir;
3018 subsubdir.sprintf("d%x/d%02x",l1,l2);
3019 if (d.exists(subsubdir.str()) && d.empty(subsubdir.str()))
3020 {
3021 d.rmdir(subsubdir.str());
3022 }
3023 }
3024 if (d.exists(subdir.str()) && d.empty(subdir.str()))
3025 {
3026 d.rmdir(subdir.str());
3027 }
3028 }
3029 }
3030}
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
const std::string & str() const
Definition dstring.h:645
bool empty(const std::string &subdir) const
Definition dir.cpp:268
bool rmdir(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:314
bool exists() const
Definition dir.cpp:262
#define Config_getInt(name)
Definition config.h:34

References Config_getBool, Config_getInt, Dir::empty(), Dir::exists(), Dir::rmdir(), DString::sprintf(), and DString::str().

Referenced by DocbookGenerator::cleanup(), HtmlGenerator::cleanup(), LatexGenerator::cleanup(), ManGenerator::cleanup(), RTFGenerator::cleanup(), and generateXML().

◆ computeQualifiedIndex()

int computeQualifiedIndex ( const DString & name)

Return the index of the last :: in the string name that is still before the first <.

Definition at line 5312 of file util.cpp.

5313{
5314 int l = static_cast<int>(name.length());
5315 int lastSepPos = -1;
5316 const char *p = name.data();
5317 int i=l-2;
5318 int sharpCount=0;
5319 // --- begin optimized version of ts=name.findRev(">::");
5320 int ts = -1;
5321 while (i>=0)
5322 {
5323 if (p[i]=='>')
5324 {
5325 if (sharpCount==0 && p[i+1]==':' && p[i+2]==':')
5326 {
5327 ts=i;
5328 break;
5329 }
5330 sharpCount++;
5331 }
5332 else if (p[i]=='<')
5333 {
5334 sharpCount--;
5335 }
5336 i--;
5337 }
5338 // --- end optimized version
5339 if (ts==-1) ts=0; else p+=++ts;
5340 for (i=ts;i<l-1;i++)
5341 {
5342 char c=*p++;
5343 if (c==':' && *p==':') lastSepPos=i;
5344 if (c=='<') break;
5345 }
5346 return lastSepPos;
5347}
const char * name(int level)
Definition latexgen.h:368

Referenced by addToMap(), addVariable(), buildFunctionList(), buildTypedefList(), getMemberFromSymbol(), SymbolResolver::Private::getResolvedSymbolRec(), and SymbolResolver::Private::getResolvedTypeRec().

◆ convertNameToFile()

DString convertNameToFile ( const DString & name,
bool allowDots,
bool allowUnderscore )

This function determines the file name on disk of an item given its name, which could be a class name with template arguments, so special characters need to be escaped.

Definition at line 2872 of file util.cpp.

2873{
2874 if (name.empty()) return name;
2875 bool shortNames = Config_getBool(SHORT_NAMES);
2876 bool createSubdirs = Config_getBool(CREATE_SUBDIRS);
2877 DString result;
2878 if (shortNames) // use short names only
2879 {
2880 std::lock_guard<std::mutex> lock(g_usedNamesMutex);
2881 auto kv = g_usedNames.find(name.str());
2882 uint32_t num=0;
2883 if (kv!=g_usedNames.end())
2884 {
2885 num = kv->second;
2886 }
2887 else
2888 {
2889 num = g_usedNamesCount;
2890 g_usedNames.emplace(name.str(),g_usedNamesCount++);
2891 }
2892 result.sprintf("a%05d",num);
2893 }
2894 else // long names
2895 {
2896 result=escapeCharsInString(name,allowDots,allowUnderscore);
2897 size_t resultLen = result.length();
2898 if (resultLen>=128) // prevent names that cannot be created!
2899 {
2900 // third algorithm based on MD5 hash
2901 result=result.left(128-32)+md5str(result.view());
2902 }
2903 }
2904 if (createSubdirs)
2905 {
2906 int l1Dir=0,l2Dir=0;
2907 int createSubdirsLevel = Config_getInt(CREATE_SUBDIRS_LEVEL);
2908 int createSubdirsBitmaskL2 = (1<<createSubdirsLevel)-1;
2909
2910 // compute md5 hash to determine sub directory to use
2911 auto md5_sig = md5hash(result.view());
2912 l1Dir = md5_sig[14] & 0xf;
2913 l2Dir = md5_sig[15] & createSubdirsBitmaskL2;
2914
2915 result.prepend(DString().sprintf("d%x/d%02x/",l1Dir,l2Dir));
2916 }
2917 //printf("*** convertNameToFile(%s)->%s\n",qPrint(name),qPrint(result));
2918 return result;
2919}
std::string_view view() const
Definition dstring.h:162
DString & prepend(const char *s)
Definition dstring.h:515
DString md5str(const std::string_view &str)
Definition md5hash.h:33
std::array< uint8_t, 16 > md5hash(const std::string_view &str)
Definition md5hash.h:26
static int g_usedNamesCount
Definition util.cpp:2864
DString escapeCharsInString(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2697
static std::mutex g_usedNamesMutex
Definition util.cpp:2863
static std::unordered_map< std::string, int > g_usedNames
Definition util.cpp:2862

References Config_getBool, Config_getInt, escapeCharsInString(), g_usedNames, g_usedNamesCount, g_usedNamesMutex, DString::left(), DString::length(), md5hash(), md5str(), DString::prepend(), DString::sprintf(), and DString::view().

Referenced by addRelatedPage(), buildExampleList(), ClassDefImpl::ClassDefImpl(), ClassDefImpl::deepCopy(), DocAnchor::DocAnchor(), DocCite::DocCite(), ModuleDefImpl::getOutputFileBase(), DocParser::handleAHref(), PageDefImpl::PageDefImpl(), CCodeParser::parseCode(), FortranCodeParser::parseCode(), VHDLCodeParser::parseCode(), RefList::RefList(), FileDefImpl::setDiskNameLocal(), NamespaceDefImpl::setFileNameLocal(), and xmlRequirementId().

◆ convertProtectionLevel()

void convertProtectionLevel ( MemberListType inListType,
Protection inProt,
MemberListType * outListType1,
MemberListType * outListType2 )

Computes for a given list type inListType, which are the the corresponding list type(s) in the base class that are to be added to this list.

So for public inheritance, the mapping is 1-1, so outListType1=inListType Private members are to be hidden completely.

For protected inheritance, both protected and public members of the base class should be joined in the protected member section.

For private inheritance, both protected and public members of the base class should be joined in the private member section.

Definition at line 4917 of file util.cpp.

4923{
4924 bool extractPrivate = Config_getBool(EXTRACT_PRIVATE);
4925
4926 // default representing 1-1 mapping
4927 *outListType1=inListType;
4928 *outListType2=MemberListType::Invalid();
4929
4930 if (inProt==Protection::Public)
4931 {
4932 if (inListType.isPrivate())
4933 {
4934 *outListType1=MemberListType::Invalid();
4935 }
4936 }
4937 else if (inProt==Protection::Protected)
4938 {
4939 if (inListType.isPrivate() || inListType.isPublic())
4940 {
4941 *outListType1=MemberListType::Invalid();
4942 }
4943 else if (inListType.isProtected())
4944 {
4945 *outListType2=inListType.toPublic();
4946 }
4947 }
4948 else if (inProt==Protection::Private)
4949 {
4950 if (inListType.isPublic() || inListType.isProtected())
4951 {
4952 *outListType1=MemberListType::Invalid();
4953 }
4954 else if (inListType.isPrivate())
4955 {
4956 if (extractPrivate)
4957 {
4958 *outListType1=inListType.toPublic();
4959 *outListType2=inListType.toProtected();
4960 }
4961 else
4962 {
4963 *outListType1=MemberListType::Invalid();
4964 }
4965 }
4966 }
4967
4968 //printf("convertProtectionLevel(type=%s prot=%d): %s,%s\n",
4969 // qPrint(inListType.to_string()),inProt,qPrint(outListType1->to_string()),qPrint(outListType2->to_string()));
4970}
constexpr bool isPrivate() const noexcept
Definition types.h:382
constexpr MemberListType toPublic() const noexcept
Definition types.h:426
static constexpr MemberListType Invalid() noexcept
Definition types.h:371
constexpr MemberListType toProtected() const noexcept
Definition types.h:438
constexpr bool isProtected() const noexcept
Definition types.h:380
ML_TYPES constexpr bool isPublic() const noexcept
Definition types.h:378

References Config_getBool, MemberListType::Invalid(), MemberListType::isPrivate(), MemberListType::isProtected(), MemberListType::isPublic(), MemberListType::toProtected(), and MemberListType::toPublic().

Referenced by ClassDefImpl::countInheritedDecMembers(), and ClassDefImpl::writeInheritedMemberDeclarations().

◆ convertToHtml()

DString convertToHtml ( const DString & s,
bool keepEntities )

Converts a string to a HTML-encoded string

Definition at line 3300 of file util.cpp.

3301{
3302 if (s.empty()) return s;
3303 DString result;
3304 result.reserve(s.length()+32);
3305 const char *p=s.data();
3306 char c = 0;
3307 while ((c=*p++))
3308 {
3309 switch (c)
3310 {
3311 case '<': result+="&lt;"; break;
3312 case '>': result+="&gt;"; break;
3313 case '&': if (keepEntities)
3314 {
3315 const char *e=p;
3316 char ce = 0;
3317 while ((ce=*e++))
3318 {
3319 if (ce==';' || (!(isId(ce) || ce=='#'))) break;
3320 }
3321 if (ce==';') // found end of an entity
3322 {
3323 // copy entry verbatim
3324 result+=c;
3325 while (p<e) result+=*p++;
3326 }
3327 else
3328 {
3329 result+="&amp;";
3330 }
3331 }
3332 else
3333 {
3334 result+="&amp;";
3335 }
3336 break;
3337 case '\'': result+="&#39;"; break;
3338 case '"': result+="&quot;"; break;
3339 default:
3340 {
3341 uint8_t uc = static_cast<uint8_t>(c);
3342 if (uc<32 && !isspace(c))
3343 {
3344 result+="&#x24";
3345 result+=hex[uc>>4];
3346 result+=hex[uc&0xF];
3347 result+=';';
3348 }
3349 else
3350 {
3351 result+=c;
3352 }
3353 }
3354 break;
3355 }
3356 }
3357 return result;
3358}
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
Definition dstring.h:217
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
static const char * hex
Definition util.cpp:80

References DString::data(), DString::empty(), hex, isId(), DString::length(), and DString::reserve().

Referenced by HtmlCodeGenerator::_writeCodeLink(), HtmlHelp::addContentsItem(), addMembersToIndex(), convertToHtmlAndTruncate(), FTVHelp::Private::generateLink(), RequirementManager::generatePage(), DefinitionImpl::navigationPathAsString(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlGenerator::startFile(), HtmlDocVisitor::startLink(), substituteHtmlKeywords(), writeClassTree(), writeClassTreeForList(), writeClassTreeToOutput(), HtmlHelpIndex::writeFields(), HtmlGenerator::writeInheritedSectionTitle(), HtmlGenerator::writeLogoAsString(), writeMapArea(), HtmlGenerator::writePageFooter(), ClassDefImpl::writeQuickMemberLinks(), FileDefImpl::writeQuickMemberLinks(), GroupDefImpl::writeQuickMemberLinks(), NamespaceDefImpl::writeQuickMemberLinks(), and HtmlGenerator::writeSearchPage().

◆ convertToId()

DString convertToId ( const DString & s)

Converts a string to a HTML id string

Definition at line 3211 of file util.cpp.

3212{
3213 if (s.empty()) return s;
3214 DString result;
3215 result.reserve(s.length()+8);
3216 const char *p = s.data();
3217 char c = 0;
3218 bool first = true;
3219 while ((c=*p++))
3220 {
3221 char encChar[4];
3222 if ((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-')
3223 { // any permissive character except _
3224 if (first && c>='0' && c<='9') result+='a'; // don't start with a digit
3225 result+=c;
3226 }
3227 else
3228 {
3229 encChar[0]='_';
3230 encChar[1]=hex[static_cast<unsigned char>(c)>>4];
3231 encChar[2]=hex[static_cast<unsigned char>(c)&0xF];
3232 encChar[3]=0;
3233 result+=encChar;
3234 }
3235 first=false;
3236 }
3237 return result;
3238}

References DString::data(), DString::empty(), hex, DString::length(), and DString::reserve().

Referenced by HtmlGenerator::endClassDiagram(), HtmlGenerator::endMemberTemplateParams(), HtmlGenerator::startGroupHeader(), HtmlGenerator::startMemberItem(), writeMemberList(), writeQuickMemberIndex(), ClassDefImpl::writeSummaryLinks(), and VhdlDocGen::writeVHDLDeclarations().

◆ convertToJSString()

DString convertToJSString ( const DString & s,
bool keepEntities = false,
bool singleQuotes = false )

Definition at line 3360 of file util.cpp.

3361{
3362 if (s.empty()) return s;
3363 DString result;
3364 result.reserve(s.length()+32);
3365 const char *p=s.data();
3366 char c = 0;
3367 while ((c=*p++))
3368 {
3369 switch (c)
3370 {
3371 case '"': if (!singleQuotes) result+="\\\""; else result+=c;
3372 break;
3373 case '\'': if (singleQuotes) result+="\\\'"; else result+=c;
3374 break;
3375 case '\\': if (*p=='u' && *(p+1)=='{') result+="\\"; // keep \u{..} unicode escapes
3376 else result+="\\\\";
3377 break;
3378 default: result+=c; break;
3379 }
3380 }
3381 return keepEntities ? result : HtmlEntityMapper::instance().convertCharEntitiesToUTF8(result);
3382}
static HtmlEntityMapper & instance()
Returns the one and only instance of the HTML entity mapper.
DString convertCharEntitiesToUTF8(const DString &s) const

References HtmlEntityMapper::convertCharEntitiesToUTF8(), DString::data(), DString::empty(), HtmlEntityMapper::instance(), DString::length(), and DString::reserve().

Referenced by generateJSLink(), generateJSNavTree(), writeJavascriptSearchData(), and writeJavasScriptSearchDataPage().

◆ convertToXML()

DString convertToXML ( const DString & s,
bool keepEntities,
const bool citeEntry )

Converts a string to an XML-encoded string

Definition at line 3241 of file util.cpp.

3242{
3243 if (s.empty()) return s;
3244 DString result;
3245 result.reserve(s.length()+32);
3246 const char *p = s.data();
3247 char c = 0;
3248 while ((c=*p++))
3249 {
3250 switch (c)
3251 {
3252 case '<': result+="&lt;"; break;
3253 case '>': result+="&gt;"; break;
3254 case '&': if (keepEntities)
3255 {
3256 const char *e=p;
3257 char ce = 0;
3258 while ((ce=*e++))
3259 {
3260 if (ce==';' || (!(isId(ce) || ce=='#'))) break;
3261 }
3262 if (ce==';') // found end of an entity
3263 {
3264 // copy entry verbatim
3265 result+=c;
3266 while (p<e) result+=*p++;
3267 }
3268 else
3269 {
3270 result+="&amp;";
3271 }
3272 }
3273 else if (citeEntry)
3274 {
3276 result,
3277 p-1,
3278 [](HtmlEntityMapper::SymType symType) { return HtmlEntityMapper::instance().xml(symType); },
3279 "&amp;");
3280 }
3281 else
3282 {
3283 result+="&amp;";
3284 }
3285 break;
3286 case '\'': result+="&apos;"; break;
3287 case '"': result+="&quot;"; break;
3288 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
3289 case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18:
3290 case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26:
3291 case 27: case 28: case 29: case 30: case 31:
3292 break; // skip invalid XML characters (see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char)
3293 default: result+=c; break;
3294 }
3295 }
3296 return result;
3297}
const char * writeHtmlEntity(T &result, const char *s, HtmlEntityMapperFunc &&mapper, const char *fallback)
Definition htmlentity.h:127
const char * xml(SymType symb) const
Access routine to the XML code of the HTML entity.

References DString::data(), DString::empty(), HtmlEntityMapper::instance(), isId(), DString::length(), DString::reserve(), HtmlEntityMapper::writeHtmlEntity(), and HtmlEntityMapper::xml().

Referenced by DocSets::addContentsItem(), EclipseHelp::addContentsItem(), Qhp::addFile(), Sitemap::addIndexFile(), Qhp::addIndexItem(), XmlDocVisitor::filter(), generateXMLForClass(), generateXMLForConcept(), generateXMLForDir(), generateXMLForFile(), generateXMLForGroup(), generateXMLForMember(), generateXMLForModule(), generateXMLForNamespace(), generateXMLForPage(), generateXMLForRequirement(), generateXMLForRequirements(), generateXMLSection(), DotDirDeps::getImgAltText(), EclipseHelp::initialize(), Qhp::initialize(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), HtmlAttribList::toString(), QhpSectionTree::traverse(), visitPreStart(), SearchIndexExternal::write(), FileDefImpl::writeClassesToTagFile(), NamespaceDefImpl::writeClassesToTagFile(), NamespaceDefImpl::writeConceptsToTagFile(), DefinitionImpl::writeDocAnchorsToTagFile(), DotNode::writeDocbook(), DotGraph::writeGraphHeader(), writeInnerClasses(), writeInnerConcepts(), writeInnerDirs(), writeInnerFiles(), writeInnerGroups(), writeInnerModules(), writeInnerNamespaces(), writeInnerPages(), writeJavascriptSearchData(), writeJavasScriptSearchDataPage(), DotNode::writeLabel(), writeListOfAllMembers(), writeMapArea(), writeMemberReference(), writeRequirementRefs(), ClassDefImpl::writeTagFile(), ConceptDefImpl::writeTagFile(), DirDefImpl::writeTagFile(), FileDefImpl::writeTagFile(), GroupDefImpl::writeTagFile(), MemberDefImpl::writeTagFile(), ModuleDefImpl::writeTagFile(), NamespaceDefImpl::writeTagFile(), PageDefImpl::writeTagFile(), RequirementManager::writeTagFile(), VhdlDocGen::writeTagFile(), writeTemplateArgumentList(), DocSets::writeToken(), DotNode::writeXML(), writeXMLLink(), and writeXMLString().

◆ copyFile()

bool copyFile ( const DString & src,
const DString & dest )

Copies the contents of file with name src to the newly created file with name dest.

Copies the file src to dest. Returns true if the copy was successful, false otherwise. When a relative path is used, is is based on the current working directory.

Returns true if successful.

Definition at line 4632 of file util.cpp.

4633{
4634 if (!Dir().copy(src.str(),dest.str()))
4635 {
4636 err("could not copy file {} to {}\n",src,dest);
4637 return false;
4638 }
4639 return true;
4640}
#define err(fmt,...)
Definition message.h:127

References err, and DString::str().

Referenced by copyExtraFiles(), copyIcon(), copyLatexStyleSheet(), copyLogo(), copyStyleSheet(), DocParser::findAndCopyImage(), FormulaManager::generateImages(), CitationManager::generatePage(), RTFGenerator::init(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), and substituteLatexKeywords().

◆ correctURL()

DString correctURL ( const DString & url,
const DString & relPath )

Corrects URL url according to the relative path relPath.

Returns the corrected URL. For absolute URLs no correction will be done.

Definition at line 4672 of file util.cpp.

4673{
4674 DString result = url;
4675 if (!relPath.empty() && !isURL(url))
4676 {
4677 result.prepend(relPath);
4678 }
4679 return result;
4680}
bool isURL(const DString &url)
Checks whether the given url starts with a supported protocol.
Definition util.cpp:4659

References DString::empty(), isURL(), and DString::prepend().

Referenced by HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), XmlDocVisitor::operator()(), and startQuickIndexItem().

◆ createHtmlUrl()

DString createHtmlUrl ( const DString & relPath,
const DString & ref,
bool islocalFile,
const DString & targetFileName,
const DString & anchor )

Definition at line 4515 of file util.cpp.

4520{
4521 DString url;
4522 if (!ref.empty())
4523 {
4524 url = externalRef(relPath,ref);
4525 }
4526 if (!targetFileName.empty())
4527 {
4528 DString fn = targetFileName;
4529 if (ref.empty())
4530 {
4531 if (!anchor.empty() && isLocalFile)
4532 {
4533 fn=""; // omit file name for local links
4534 }
4535 else
4536 {
4537 url = relPath;
4538 }
4539 }
4540 url+=fn;
4541 }
4542 if (!anchor.empty())
4543 {
4544 if (!url.endsWith("=")) url+="#";
4545 url+=anchor;
4546 }
4547 //printf("createHtmlUrl(relPath=%s,local=%d,target=%s,anchor=%s)=%s\n",qPrint(relPath),isLocalFile,qPrint(targetFileName),qPrint(anchor),qPrint(url));
4548 return url;
4549}
bool endsWith(const char *s) const
Definition dstring.h:617
DString externalRef(const DString &relPath, const DString &ref)
Definition util.cpp:4551

References DString::empty(), DString::endsWith(), and externalRef().

Referenced by HtmlCodeGenerator::_writeCodeLink(), RequirementManager::generatePage(), HtmlDocVisitor::startLink(), HtmlGenerator::startTextLink(), HtmlGenerator::writeObjectLink(), and HtmlCodeGenerator::writeTooltip().

◆ createSubDirs()

void createSubDirs ( const Dir & d)

Definition at line 2978 of file util.cpp.

2979{
2980 if (Config_getBool(CREATE_SUBDIRS))
2981 {
2982 // create up to 4096 subdirectories
2983 int createSubdirsLevelPow2 = 1 << Config_getInt(CREATE_SUBDIRS_LEVEL);
2984 for (int l1=0; l1<16; l1++)
2985 {
2986 DString subdir;
2987 subdir.sprintf("d%x",l1);
2988 if (!d.exists(subdir.str()) && !d.mkdir(subdir.str()))
2989 {
2990 term("Failed to create output directory '{}'\n",subdir);
2991 }
2992 for (int l2=0; l2<createSubdirsLevelPow2; l2++)
2993 {
2994 DString subsubdir;
2995 subsubdir.sprintf("d%x/d%02x",l1,l2);
2996 if (!d.exists(subsubdir.str()) && !d.mkdir(subsubdir.str()))
2997 {
2998 term("Failed to create output directory '{}'\n",subsubdir);
2999 }
3000 }
3001 }
3002 }
3003}
bool mkdir(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:300
#define term(fmt,...)
Definition message.h:137

References Config_getBool, Config_getInt, Dir::exists(), Dir::mkdir(), DString::sprintf(), DString::str(), and term.

Referenced by generateXML(), DocbookGenerator::init(), HtmlGenerator::init(), LatexGenerator::init(), ManGenerator::init(), RTFGenerator::init(), ClassDefImpl::writeQuickMemberLinks(), FileDefImpl::writeQuickMemberLinks(), GroupDefImpl::writeQuickMemberLinks(), and NamespaceDefImpl::writeQuickMemberLinks().

◆ demangleCSharpGenericName()

DString demangleCSharpGenericName ( const DString & name,
const DString & templArgs )

Definition at line 5380 of file util.cpp.

5381{
5382 DString result=name;
5383 if (result.endsWith("-g"))
5384 {
5385 size_t idx = result.find('-');
5386 result = result.left(idx)+templArgs;
5387 }
5388 return result;
5389}

References DString::endsWith(), DString::find(), and DString::left().

Referenced by ClassDefImpl::className().

◆ detab()

DString detab ( const DString & s,
size_t & refIndent )

Definition at line 5207 of file util.cpp.

5208{
5209 int tabSize = Config_getInt(TAB_SIZE);
5210 size_t size = s.length();
5211 DString result;
5212 result.reserve(size+256);
5213 const char *data = s.data();
5214 size_t i=0;
5215 int col=0;
5216 constexpr auto doxy_nbsp = "&_doxy_nbsp;"; // doxygen escape command for UTF-8 nbsp
5217 const int maxIndent=1000000; // value representing infinity
5218 int minIndent=maxIndent;
5219 bool skip = false;
5220 while (i<size)
5221 {
5222 char c = data[i++];
5223 switch(c)
5224 {
5225 case '\t': // expand tab
5226 {
5227 int stop = tabSize - (col%tabSize);
5228 //printf("expand at %d stop=%d\n",col,stop);
5229 col+=stop;
5230 while (stop--) result+=' ';
5231 }
5232 break;
5233 case '\\':
5234 if (skip && data[i] == '\\' && i+8<size && literal_at(data+i+1,"endiskip"))
5235 {
5236 // literal backslash directly followed by , e.g. `\` in a code span
5237 result+=c;
5238 col++;
5239 }
5240 else if (data[i] == '\\') // escaped command -> ignore
5241 {
5242 result+=c;
5243 result+=data[i++];
5244 col+=2;
5245 }
5246 else if (i+5<size && literal_at(data+i,"iskip")) // command
5247 {
5248 i+=5;
5249 skip = true;
5250 }
5251 else if (i+8<size && literal_at(data+i,"endiskip")) // command
5252 {
5253 i+=8;
5254 skip = false;
5255 }
5256 else // some other command
5257 {
5258 result+=c;
5259 col++;
5260 }
5261 break;
5262 case '\n': // reset column counter
5263 result+=c;
5264 col=0;
5265 break;
5266 case ' ': // increment column counter
5267 result+=c;
5268 col++;
5269 break;
5270 default: // non-whitespace => update minIndent
5271 if (static_cast<signed char>(c)<0 && i<size) // multibyte sequence
5272 {
5273 // special handling of the UTF-8 nbsp character 0xC2 0xA0
5274 int nb = isUTF8NonBreakableSpace(data);
5275 if (nb>0)
5276 {
5277 result+=doxy_nbsp;
5278 i+=nb-1;
5279 }
5280 else
5281 {
5282 int bytes = getUTF8CharNumBytes(c);
5283 for (int j=0;j<bytes-1 && c;j++)
5284 {
5285 result+=c;
5286 c = data[i++];
5287 }
5288 result+=c;
5289 }
5290 }
5291 else
5292 {
5293 result+=c;
5294 }
5295 if (!skip && col<minIndent) minIndent=col;
5296 col++;
5297 }
5298 }
5299 if (minIndent!=maxIndent) refIndent=minIndent; else refIndent=0;
5300 //printf("detab(\n%s\n)=[\n%s\n]\n",qPrint(s),qPrint(out.get()));
5301 return result;
5302}
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
Definition stringutil.h:101
int isUTF8NonBreakableSpace(const char *input)
Check if the first character pointed at by input is a non-breakable whitespace character.
Definition utf8.cpp:232
uint8_t getUTF8CharNumBytes(char c)
Returns the number of bytes making up a single UTF8 character given the first byte in the sequence.
Definition utf8.cpp:27

References Config_getInt, DString::data(), getUTF8CharNumBytes(), isUTF8NonBreakableSpace(), DString::length(), literal_at(), and DString::reserve().

Referenced by FileDefImpl::parseSource(), Markdown::process(), DocParser::readTextFileByName(), readTextFileByName(), MemberDefImpl::setInitializer(), DefinitionImpl::writeInlineCode(), and FileDefImpl::writeSourceBody().

◆ determineAbsoluteIncludeName()

DString determineAbsoluteIncludeName ( const DString & curFile,
const DString & incFileName )

Definition at line 2938 of file util.cpp.

2939{
2940 bool searchIncludes = Config_getBool(SEARCH_INCLUDES);
2941 DString absIncFileName = incFileName;
2942 FileInfo fi(curFile.str());
2943 if (fi.exists())
2944 {
2945 DString absName = fi.dirPath(true)+"/"+incFileName;
2946 FileInfo fi2(absName.str());
2947 if (fi2.exists())
2948 {
2949 absIncFileName=fi2.absFilePath();
2950 }
2951 else if (searchIncludes) // search in INCLUDE_PATH as well
2952 {
2953 StringVector includePath = Config_getList(INCLUDE_PATH);
2954 for (const auto &incPath : includePath)
2955 {
2956 FileInfo fi3(incPath);
2957 if (fi3.exists() && fi3.isDir())
2958 {
2959 absName = fi3.absFilePath()+"/"+incFileName;
2960 //printf("trying absName=%s\n",qPrint(absName));
2961 FileInfo fi4(absName.str());
2962 if (fi4.exists())
2963 {
2964 absIncFileName=fi4.absFilePath();
2965 break;
2966 }
2967 //printf( "absIncFileName = %s\n", qPrint(absIncFileName) );
2968 }
2969 }
2970 }
2971 //printf( "absIncFileName = %s\n", qPrint(absIncFileName) );
2972 }
2973 return absIncFileName;
2974}
Minimal replacement for QFileInfo.
Definition fileinfo.h:26
#define Config_getList(name)
Definition config.h:38
std::vector< std::string > StringVector
Definition containers.h:33

References FileInfo::absFilePath(), Config_getBool, Config_getList, FileInfo::dirPath(), FileInfo::exists(), FileInfo::isDir(), and DString::str().

Referenced by readIncludeFile(), and ModuleManager::resolveImports().

◆ escapeCharsInString()

DString escapeCharsInString ( const DString & name,
bool allowDots,
bool allowUnderscore = false )

Definition at line 2697 of file util.cpp.

2698{
2699 if (name.empty()) return name;
2700 bool caseSenseNames = useCaseSenseNames();
2701 bool allowUnicodeNames = Config_getBool(ALLOW_UNICODE_NAMES);
2702 DString result;
2703 result.reserve(name.length()+8);
2704 signed char c = 0;
2705 const char *p=name.data();
2706 while ((c=*p++)!=0)
2707 {
2708 switch(c)
2709 {
2710 case '_': if (allowUnderscore) result+='_'; else result+="__"; break;
2711 case '-': result+='-'; break;
2712 case ':': result+="_1"; break;
2713 case '/': result+="_2"; break;
2714 case '<': result+="_3"; break;
2715 case '>': result+="_4"; break;
2716 case '*': result+="_5"; break;
2717 case '&': result+="_6"; break;
2718 case '|': result+="_7"; break;
2719 case '.': if (allowDots) result+='.'; else result+="_8"; break;
2720 case '!': result+="_9"; break;
2721 case ',': result+="_00"; break;
2722 case ' ': result+="_01"; break;
2723 case '{': result+="_02"; break;
2724 case '}': result+="_03"; break;
2725 case '?': result+="_04"; break;
2726 case '^': result+="_05"; break;
2727 case '%': result+="_06"; break;
2728 case '(': result+="_07"; break;
2729 case ')': result+="_08"; break;
2730 case '+': result+="_09"; break;
2731 case '=': result+="_0a"; break;
2732 case '$': result+="_0b"; break;
2733 case '\\': result+="_0c"; break;
2734 case '@': result+="_0d"; break;
2735 case ']': result+="_0e"; break;
2736 case '[': result+="_0f"; break;
2737 case '#': result+="_0g"; break;
2738 case '"': result+="_0h"; break;
2739 case '~': result+="_0i"; break;
2740 case '\'': result+="_0j"; break;
2741 case ';': result+="_0k"; break;
2742 case '`': result+="_0l"; break;
2743 default:
2744 if (c<0)
2745 {
2746 bool doEscape = true;
2747 if (allowUnicodeNames)
2748 {
2749 int charLen = getUTF8CharNumBytes(c);
2750 if (charLen>0)
2751 {
2752 result+=DString(p-1,charLen);
2753 p+=charLen;
2754 doEscape = false;
2755 }
2756 }
2757 if (doEscape) // not a valid unicode char or escaping needed
2758 {
2759 char ids[5];
2760 unsigned char id = static_cast<unsigned char>(c);
2761 ids[0]='_';
2762 ids[1]='x';
2763 ids[2]=hex[id>>4];
2764 ids[3]=hex[id&0xF];
2765 ids[4]=0;
2766 result+=ids;
2767 }
2768 }
2769 else if (caseSenseNames || !isupper(c))
2770 {
2771 result+=c;
2772 }
2773 else
2774 {
2775 result+='_';
2776 result+=static_cast<char>(tolower(c));
2777 }
2778 break;
2779 }
2780 }
2781 return result;
2782}
bool useCaseSenseNames()
Returns true if the names of the symbols can be case sensitive.
Definition util.cpp:2688

References Config_getBool, getUTF8CharNumBytes(), hex, DString::reserve(), and useCaseSenseNames().

Referenced by convertNameToFile(), DotClassGraph::getMapLabel(), DotDirDeps::getMapLabel(), DotGfxHierarchyTable::getMapLabel(), DotGroupCollaboration::getMapLabel(), DotInclDepGraph::getMapLabel(), markdownFileNameToId(), and PageDefImpl::writeDocumentation().

◆ externalLinkTarget()

DString externalLinkTarget ( const bool parent = false)

Definition at line 4504 of file util.cpp.

4505{
4506 bool extLinksInWindow = Config_getBool(EXT_LINKS_IN_WINDOW);
4507 if (extLinksInWindow)
4508 return "target=\"_blank\" ";
4509 else if (parent)
4510 return "target=\"_parent\" ";
4511 else
4512 return "";
4513}
constexpr DocNodeVariant * parent(DocNodeVariant *n)
returns the parent node of a given node n or nullptr if the node has no parent.
Definition docnode.h:1335

References Config_getBool, and parent().

Referenced by HtmlCodeGenerator::_writeCodeLink(), FTVHelp::Private::generateLink(), Markdown::Private::processLink(), replaceRef(), HtmlGenerator::startIndexItem(), HtmlDocVisitor::startLink(), HtmlGenerator::writeInheritedSectionTitle(), writeMapArea(), and HtmlGenerator::writeObjectLink().

◆ externalRef()

DString externalRef ( const DString & relPath,
const DString & ref )

Resolve a reference via a tagfile reference ref. If after resolving the reference the result points to a relative path then relPath is prepended to create the correct link.

Definition at line 4551 of file util.cpp.

4552{
4553 DString result;
4554 if (!ref.empty())
4555 {
4556 auto it = Doxygen::tagDestinationMap.find(ref.str());
4558 {
4559 result = it->second;
4560 size_t l = result.length();
4561 if (!relPath.empty() && l>0 && result.at(0)=='.')
4562 { // relative path -> prepend relPath.
4563 result.prepend(relPath);
4564 l+=relPath.length();
4565 }
4566 if (l>0 && result.at(l-1)!='/') result+='/';
4567 }
4568 }
4569 else
4570 {
4571 result = relPath;
4572 }
4573 return result;
4574}
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
static StringMap tagDestinationMap
Definition doxygen.h:109
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:180

References DString::at(), DString::empty(), end(), DString::length(), DString::prepend(), DString::str(), and Doxygen::tagDestinationMap.

Referenced by HtmlHelp::addContentsItem(), convertMapFile(), createHtmlUrl(), generateJSLink(), FTVHelp::Private::generateLink(), replaceRef(), HtmlGenerator::startIndexItem(), LayoutNavEntry::url(), HtmlGenerator::writeInheritedSectionTitle(), writeJavasScriptSearchDataPage(), and writeMapArea().

◆ extractBeginRawStringDelimiter()

DString extractBeginRawStringDelimiter ( const char * rawStart)

Definition at line 5391 of file util.cpp.

5392{
5393 DString text=rawStart;
5394 size_t i = text.find('"');
5396 return text.mid(i+1,text.length()-i-2); // text=...R"xyz( -> delimiter=xyz
5397}
#define ASSERT(x)
Definition message.h:142

References ASSERT, DString::find(), DString::length(), DString::mid(), and DString::npos.

◆ extractClassNameFromType()

int extractClassNameFromType ( const DString & type,
int & pos,
DString & name,
DString & templSpec,
SrcLangExt lang )

Extracts a (sub-)string from type starting at pos that could form a class. The index of the match is returned and the found class name and a template argument list templSpec. If -1 is returned there are no more matches.

Definition at line 3389 of file util.cpp.

3390{
3391 AUTO_TRACE("type='{}' pos={} name='{}' lang={}",type,pos,name,lang);
3392 static const reg::Ex re_norm(R"(\a[\w:]*)");
3393 static const reg::Ex re_fortran(R"(\a[\w:()=]*)");
3394 const reg::Ex *re = &re_norm;
3395
3396 name.clear();
3397 templSpec.clear();
3398 if (type.empty())
3399 {
3400 AUTO_TRACE_EXIT("empty type");
3401 return -1;
3402 }
3403 size_t typeLen=type.length();
3404 if (typeLen>0)
3405 {
3406 if (lang == SrcLangExt::Fortran)
3407 {
3408 if (type[pos]==',')
3409 {
3410 AUTO_TRACE_EXIT("comma");
3411 return -1;
3412 }
3413 if (!type.lower().startsWith("type"))
3414 {
3415 re = &re_fortran;
3416 }
3417 }
3418 std::string s = type.str();
3419 reg::Iterator it(s,*re,static_cast<int>(pos));
3421
3422 if (it!=end)
3423 {
3424 const auto &match = *it;
3425 size_t i = match.position();
3426 size_t l = match.length();
3427 size_t ts = i+l;
3428 size_t te = ts;
3429 size_t tl = 0;
3430
3431 while (ts<typeLen && type[static_cast<uint32_t>(ts)]==' ') { ts++; tl++; } // skip any whitespace
3432 if (ts<typeLen && type[static_cast<uint32_t>(ts)]=='<') // assume template instance
3433 {
3434 // locate end of template
3435 te=ts+1;
3436 int brCount=1;
3437 while (te<typeLen && brCount!=0)
3438 {
3439 if (type[static_cast<uint32_t>(te)]=='<')
3440 {
3441 if (te<typeLen-1 && type[static_cast<uint32_t>(te)+1]=='<') te++; else brCount++;
3442 }
3443 if (type[static_cast<uint32_t>(te)]=='>')
3444 {
3445 if (te<typeLen-1 && type[static_cast<uint32_t>(te)+1]=='>') te++; else brCount--;
3446 }
3447 te++;
3448 }
3449 }
3450 name = match.str();
3451 if (te>ts)
3452 {
3453 templSpec = DString(type).mid(ts,te-ts);
3454 tl+=te-ts;
3455 pos=static_cast<int>(i+l+tl);
3456 }
3457 else // no template part
3458 {
3459 pos=static_cast<int>(i+l);
3460 }
3461 //printf("extractClassNameFromType([in] type=%s,[out] pos=%d,[out] name=%s,[out] templ=%s)=true i=%d\n",
3462 // qPrint(type),pos,qPrint(name),qPrint(templSpec),i);
3463 AUTO_TRACE_EXIT("pos={} templSpec='{}' return={}",pos,templSpec,i);
3464 return static_cast<int>(i);
3465 }
3466 }
3467 pos = static_cast<int>(typeLen);
3468 //printf("extractClassNameFromType([in] type=%s,[out] pos=%d,[out] name=%s,[out] templ=%s)=false\n",
3469 // qPrint(type),pos,qPrint(name),qPrint(templSpec));
3470 AUTO_TRACE_EXIT("not found");
3471 return -1;
3472}
void clear()
Definition dstring.h:214
DString lower() const
Definition dstring.h:326
bool startsWith(const char *s) const
Definition dstring.h:600
Class representing a regular expression.
Definition regex.h:39
Class to iterate through matches.
Definition regex.h:245
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:861

References AUTO_TRACE, AUTO_TRACE_EXIT, DString::clear(), DString::empty(), end(), DString::length(), DString::lower(), DString::mid(), DString::startsWith(), and DString::str().

Referenced by extractCanonicalType(), findUsedClassesForClass(), stripClassName(), and stripClassName().

◆ extractEndRawStringDelimiter()

DString extractEndRawStringDelimiter ( const char * rawEnd)

Definition at line 5399 of file util.cpp.

5400{
5401 DString text=rawEnd;
5402 return text.mid(1,text.length()-2); // text=)xyz" -> delimiter=xyz
5403}

References DString::length(), and DString::mid().

◆ extractNamespaceName()

void extractNamespaceName ( const DString & scopeName,
DString & className,
DString & namespaceName,
bool allowEmptyClass )

Input is a scopeName, output is the scopename split into a namespace part (as large as possible) and a classname part.

Definition at line 3035 of file util.cpp.

3038{
3039 DString clName=scopeName;
3040 NamespaceDef *nd = nullptr;
3041 size_t i=0;
3042 int p=0;
3043 if (!clName.empty() && (nd=getResolvedNamespace(clName)) && getClass(clName)==nullptr)
3044 { // the whole name is a namespace (and not a class)
3045 namespaceName=nd->name();
3046 className.clear();
3047 goto done;
3048 }
3049 p=static_cast<int>(clName.length())-2;
3050 while (p>=0 && (i=clName.rfind("::",p))!=DString::npos)
3051 // see if the first part is a namespace (and not a class)
3052 {
3053 //printf("Trying %s\n",qPrint(clName.left(i)));
3054 if (i>0 && (nd=getResolvedNamespace(clName.left(i))) && getClass(clName.left(i))==nullptr)
3055 {
3056 //printf("found!\n");
3057 namespaceName=nd->name();
3058 className=clName.mid(i+2);
3059 goto done;
3060 }
3061 p=static_cast<int>(i)-2; // try a smaller piece of the scope
3062 }
3063 //printf("not found!\n");
3064
3065 // not found, so we just have to guess.
3066 className=scopeName;
3067 namespaceName.clear();
3068
3069done:
3070 if (className.empty() && !namespaceName.empty() && !allowEmptyClass)
3071 {
3072 // class and namespace with the same name, correct to return the class.
3073 className=namespaceName;
3074 namespaceName.clear();
3075 }
3076 //printf("extractNamespace '%s' => '%s|%s'\n",qPrint(scopeName),
3077 // qPrint(className),qPrint(namespaceName));
3078 if (className.endsWith("-p"))
3079 {
3080 className = className.left(className.length()-2);
3081 }
3082 return;
3083}
virtual const DString & name() const =0
An abstract interface of a namespace symbol.
ClassDef * getClass(const DString &n)
NamespaceDef * getResolvedNamespace(const DString &name)

References DString::clear(), DString::empty(), DString::endsWith(), getClass(), getResolvedNamespace(), DString::left(), DString::length(), DString::mid(), Definition::name(), DString::npos, and DString::rfind().

Referenced by addClassToContext(), addConceptToContext(), findMember(), and writeAlphabeticalClassList().

◆ fileToString()

DString fileToString ( const DString & name,
bool filter = false,
bool isSourceCode = false )

reads a file with name name and returns it as a string. If filter is true the file will be filtered by any user specified input filter. If name is "-" the string will be read from standard input.

Definition at line 1058 of file util.cpp.

1059{
1060 if (name.empty()) return DString();
1061 bool fileOpened=false;
1062 if (name[0]=='-' && name[1]==0) // read from stdin
1063 {
1064 std::string contents;
1065 std::string line;
1066 while (getline(std::cin,line))
1067 {
1068 contents+=line+'\n';
1069 }
1070 return contents;
1071 }
1072 else // read from file
1073 {
1074 FileInfo fi(name.str());
1075 if (!fi.exists() || !fi.isFile())
1076 {
1077 err("file '{}' not found\n",name);
1078 return "";
1079 }
1080 std::string buf;
1081 fileOpened=readInputFile(name,buf,ReadInputFileOptions().setFilter(filter).setIsSourceCode(isSourceCode));
1082 if (fileOpened)
1083 {
1084 addTerminalCharIfMissing(buf,'\n');
1085 return buf;
1086 }
1087 }
1088 if (!fileOpened)
1089 {
1090 err("cannot open file '{}' for reading\n",name);
1091 }
1092 return "";
1093}
void addTerminalCharIfMissing(std::string &s, char c)
Definition stringutil.h:87
bool readInputFile(const DString &fileName, std::string &contents, const ReadInputFileOptions &options)
read a file name fileName and optionally filter and transcode it
Definition util.cpp:4383

References addTerminalCharIfMissing(), err, FileInfo::exists(), FileInfo::isFile(), and readInputFile().

Referenced by createDVIFile(), extractBoundingBox(), getConvertLatexMacro(), HtmlGenerator::init(), LatexGenerator::init(), LayoutDocManager::parse(), parseInput(), FileDefImpl::parseSource(), parseTagFile(), DocParser::readTextFileByName(), readTextFileByName(), runMermaid(), runPlantumlContent(), FileDefImpl::writeSourceBody(), HtmlGenerator::writeStyleInfo(), and writeXMLCodeBlock().

◆ filterTitle()

DString filterTitle ( const DString & title)

Definition at line 4467 of file util.cpp.

4468{
4469 std::string tf;
4470 std::string t = title.str();
4471 static const reg::Ex re(R"(%[a-z_A-Z]+)");
4472 reg::Iterator it(t,re);
4474 size_t p = 0;
4475 for (; it!=end ; ++it)
4476 {
4477 const auto &match = *it;
4478 size_t i = match.position();
4479 size_t l = match.length();
4480 if (i>p) tf+=t.substr(p,i-p);
4481 tf+=match.str().substr(1); // skip %
4482 p=i+l;
4483 }
4484 tf+=t.substr(p);
4485 return tf;
4486}

References end(), and DString::str().

Referenced by addToIndices(), createJavaScriptSearchIndex(), PerlModGenerator::generatePerlModForPage(), generateSqlite3ForPage(), generateXMLForPage(), generateXMLForRequirement(), generateXMLForRequirements(), parseCommentAsHtml(), SearchIndexExternal::setCurrentDoc(), HtmlGenerator::startFile(), and writeJavasScriptSearchDataPage().

◆ findExampleFilePath()

DString findExampleFilePath ( const DString & file,
bool & ambig )

Definition at line 2460 of file util.cpp.

2461{
2462 ambig=false;
2463 DString result;
2464 bool found=false;
2465 if (!found)
2466 {
2467 FileInfo fi(file.str());
2468 if (fi.exists())
2469 {
2470 result=fi.absFilePath();
2471 found=true;
2472 }
2473 }
2474 if (!found)
2475 {
2476 StringVector examplePathList = Config_getList(EXAMPLE_PATH);
2477 for (const auto &s : examplePathList)
2478 {
2479 std::string absFileName = s+(Portable::pathSeparator()+file).str();
2480 FileInfo fi(absFileName);
2481 if (fi.exists())
2482 {
2483 result=fi.absFilePath();
2484 found=true;
2485 }
2486 }
2487 }
2488
2489 if (!found)
2490 {
2491 // as a fallback we also look in the exampleNameDict
2493 if (fd && !ambig)
2494 {
2495 result=fd->absFilePath();
2496 }
2497 }
2498 return result;
2499}
static FileNameLinkedMap * exampleNameLinkedMap
Definition doxygen.h:95
A model of a file symbol.
Definition filedef.h:97
virtual DString absFilePath() const =0
FileDef * findFileDef(const DString &n, bool &ambig) const
Returns the file definition in fnMap that matches the file name n.
Definition filename.cpp:38
DString pathSeparator()
Definition portable.cpp:390

References FileDef::absFilePath(), FileInfo::absFilePath(), Config_getList, Doxygen::exampleNameLinkedMap, FileInfo::exists(), FileNameLinkedMap::findFileDef(), Portable::pathSeparator(), and DString::str().

Referenced by readIncludeFile(), and DocParser::readTextFileByName().

◆ getDefs()

GetDefResult getDefs ( const GetDefInput & input)

Definition at line 1874 of file util.cpp.

1875{
1876 GetDefResult result;
1877 if (input.memberName.empty()) return result;
1878 AUTO_TRACE("scopeName={},memberName={},forceEmptyScope={}",
1879 input.scopeName,input.memberName,input.forceEmptyScope);
1880
1881 //printf("@@ --- getDefsNew(%s,%s)-----------\n",qPrint(scName),qPrint(mbName));
1882 const Definition *scope = Doxygen::globalScope;
1883 SymbolResolver resolver;
1884 if (input.currentFile) resolver.setFileScope(input.currentFile);
1885 if (!input.scopeName.empty() && !input.forceEmptyScope)
1886 {
1887 scope = resolver.resolveSymbol(scope,input.scopeName);
1888 }
1889 if (scope==Doxygen::globalScope)
1890 {
1891 scope = input.currentFile;
1892 }
1893 //printf("@@ -> found scope scope=%s member=%s out=%s\n",qPrint(input.scopeName),qPrint(input.memberName),qPrint(scope?scope->name():""));
1894 //
1895 const Definition *symbol = resolver.resolveSymbol(scope,input.memberName,input.args,input.checkCV,input.insideCode,true);
1896 //printf("@@ -> found symbol in=%s out=%s\n",qPrint(input.memberName),qPrint(symbol?symbol->qualifiedName():DString()));
1897 if (symbol && symbol->definitionType()==Definition::TypeMember)
1898 {
1899 result.md = toMemberDef(symbol);
1900 result.cd = result.md->getClassDef();
1901 if (result.cd==nullptr) result.nd = result.md->getNamespaceDef();
1902 if (result.cd==nullptr && result.nd==nullptr) result.fd = result.md->getFileDef();
1903 result.gd = result.md->getGroupDef();
1904 result.found = true;
1905 }
1906 else if (symbol && symbol->definitionType()==Definition::TypeClass)
1907 {
1908 result.cd = toClassDef(symbol);
1909 result.found = true;
1910 }
1911 else if (symbol && symbol->definitionType()==Definition::TypeNamespace)
1912 {
1913 result.nd = toNamespaceDef(symbol);
1914 result.found = true;
1915 }
1916 else if (symbol && symbol->definitionType()==Definition::TypeConcept)
1917 {
1918 result.cnd = toConceptDef(symbol);
1919 result.found = true;
1920 }
1921 else if (symbol && symbol->definitionType()==Definition::TypeModule)
1922 {
1923 result.modd = toModuleDef(symbol);
1924 result.found = true;
1925 }
1926 return result;
1927}
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual DefType definitionType() const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
virtual const ClassDef * getClassDef() const =0
virtual GroupDef * getGroupDef()=0
virtual const FileDef * getFileDef() const =0
virtual const NamespaceDef * getNamespaceDef() const =0
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.
void setFileScope(const FileDef *fd)
Sets or updates the file scope using when resolving symbols.
ClassDef * toClassDef(Definition *d)
ConceptDef * toConceptDef(Definition *d)
MemberDef * toMemberDef(Definition *d)
ModuleDef * toModuleDef(Definition *d)
NamespaceDef * toNamespaceDef(Definition *d)
bool forceEmptyScope
Definition util.h:102
const FileDef * currentFile
Definition util.h:103
bool insideCode
Definition util.h:105
DString args
Definition util.h:101
DString memberName
Definition util.h:100
bool checkCV
Definition util.h:104
DString scopeName
Definition util.h:99
const MemberDef * md
Definition util.h:112
const ConceptDef * cnd
Definition util.h:117
const FileDef * fd
Definition util.h:114
const ModuleDef * modd
Definition util.h:118
const GroupDef * gd
Definition util.h:116
bool found
Definition util.h:111
const ClassDef * cd
Definition util.h:113
const NamespaceDef * nd
Definition util.h:115

References GetDefInput::args, AUTO_TRACE, GetDefResult::cd, GetDefInput::checkCV, GetDefResult::cnd, GetDefInput::currentFile, Definition::definitionType(), DString::empty(), GetDefResult::fd, GetDefInput::forceEmptyScope, GetDefResult::found, GetDefResult::gd, MemberDef::getClassDef(), MemberDef::getFileDef(), MemberDef::getGroupDef(), MemberDef::getNamespaceDef(), Doxygen::globalScope, GetDefInput::insideCode, GetDefResult::md, GetDefInput::memberName, GetDefResult::modd, GetDefResult::nd, SymbolResolver::resolveSymbol(), GetDefInput::scopeName, SymbolResolver::setFileScope(), toClassDef(), toConceptDef(), toMemberDef(), toModuleDef(), toNamespaceDef(), Definition::TypeClass, Definition::TypeConcept, Definition::TypeMember, Definition::TypeModule, and Definition::TypeNamespace.

Referenced by DocParser::findDocsForMemberOrCompound(), getLinkInScope(), getLinkInScope(), linkifyText(), and resolveRef().

◆ getDotImageExtension() [1/2]

DString getDotImageExtension ( )

Returns the file extension to use for dot files as specified via the DOT_IMAGE_FORMAT configuration option.

Definition at line 4977 of file util.cpp.

4978{
4979 return getDotImageExtension(Config_getEnumAsString(DOT_IMAGE_FORMAT));
4980}
#define Config_getEnumAsString(name)
Definition config.h:36
DString getDotImageExtension()
Definition util.cpp:4977

References Config_getEnumAsString, and getDotImageExtension().

Referenced by MermaidManager::convertToImageFormat(), RTFGenerator::endCallGraph(), RTFGenerator::endDirDepGraph(), RTFGenerator::endDotGraph(), RTFGenerator::endInclDepGraph(), DotGraph::generateCode(), getDotImageExtension(), DotGraph::imgName(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), DotRunner::run(), DocbookDocVisitor::startDotFile(), TranslatorAfrikaans::trLegendDocs(), TranslatorArabic::trLegendDocs(), TranslatorArmenian::trLegendDocs(), TranslatorBrazilian::trLegendDocs(), TranslatorBulgarian::trLegendDocs(), TranslatorCatalan::trLegendDocs(), TranslatorChinese::trLegendDocs(), TranslatorChinesetraditional::trLegendDocs(), TranslatorCroatian::trLegendDocs(), TranslatorCzech::trLegendDocs(), TranslatorDanish::trLegendDocs(), TranslatorDutch::trLegendDocs(), TranslatorEnglish::trLegendDocs(), TranslatorEsperanto::trLegendDocs(), TranslatorFinnish::trLegendDocs(), TranslatorFrench::trLegendDocs(), TranslatorGerman::trLegendDocs(), TranslatorGreek::trLegendDocs(), TranslatorHindi::trLegendDocs(), TranslatorHungarian::trLegendDocs(), TranslatorIndonesian::trLegendDocs(), TranslatorItalian::trLegendDocs(), TranslatorJapanese::trLegendDocs(), TranslatorKorean::trLegendDocs(), TranslatorLatvian::trLegendDocs(), TranslatorLithuanian::trLegendDocs(), TranslatorMacedonian::trLegendDocs(), TranslatorNorwegian::trLegendDocs(), TranslatorPersian::trLegendDocs(), TranslatorPolish::trLegendDocs(), TranslatorPortuguese::trLegendDocs(), TranslatorRomanian::trLegendDocs(), TranslatorRussian::trLegendDocs(), TranslatorSerbian::trLegendDocs(), TranslatorSerbianCyrillic::trLegendDocs(), TranslatorSlovak::trLegendDocs(), TranslatorSlovene::trLegendDocs(), TranslatorSpanish::trLegendDocs(), TranslatorSwedish::trLegendDocs(), TranslatorTurkish::trLegendDocs(), TranslatorUkrainian::trLegendDocs(), TranslatorVietnamese::trLegendDocs(), DocbookDocVisitor::writeDotFile(), RTFDocVisitor::writeDotFile(), writeDotGraphFromFile(), writeDotImageMapFromFile(), DotLegendGraph::writeGraph(), HtmlDocVisitor::writeMscFile(), and HtmlDocVisitor::writePlantUMLFile().

◆ getDotImageExtension() [2/2]

DString getDotImageExtension ( const DString & format)

Returns the file extension to use for dot files as specified via the argument format.

Definition at line 4981 of file util.cpp.

4982{
4983 size_t i= format.find(':'); // strip renderer part when using e.g. 'png:cairo:gd' as format
4984 return i==DString::npos ? format : format.left(i);
4985}

References DString::find(), DString::left(), and DString::npos.

◆ getDotImageExtensionGenerated()

DString getDotImageExtensionGenerated ( const DString & format)

Definition at line 4987 of file util.cpp.

4988{
4989 StringVector splitExt = split(format.str(),":");
4990 DString extGen;
4991 for (size_t i = splitExt.size(); i > 0; )
4992 {
4993 --i;
4994 extGen += splitExt[i] + (i!=0 ? "." : "");
4995 }
4996 return extGen;
4997}
StringVector split(const std::string &s, const std::string &delimiter, bool retainEmpty=false)
split input string s by string delimiter delimiter.
Definition stringutil.h:119

References split(), and DString::str().

Referenced by DotRunner::run().

◆ getEncoding()

DString getEncoding ( const FileInfo & fi)

Definition at line 4490 of file util.cpp.

4491{
4492 InputFileEncoding elem;
4493 auto getter = [](const InputFileEncoding &e) { return e.pattern.str(); };
4494 if (fi.match(Doxygen::inputFileEncodingList,useCaseSenseNames(),&elem,getter)) // check for file specific encoding
4495 {
4496 return elem.encoding;
4497 }
4498 else // fall back to default encoding
4499 {
4500 return Config_getString(INPUT_ENCODING);
4501 }
4502}
static InputFileEncodingList inputFileEncodingList
Definition doxygen.h:131
bool match(const PatternList &patList, bool caseSenseNames, PatternElem *elem=nullptr, PatternGet getter=[](const std::string &s){ return s;}) const
Match the file name against a list of patterns.
Definition fileinfo.h:60
#define Config_getString(name)
Definition config.h:32
DString encoding
Definition doxygen.h:63

References Config_getString, InputFileEncoding::encoding, Doxygen::inputFileEncodingList, FileInfo::match(), and useCaseSenseNames().

Referenced by readCodeFragment(), and readInputFile().

◆ getFileFilter()

DString getFileFilter ( const DString & name,
bool isSourceCode )

looks for a filter for the file name. Returns the name of the filter if there is a match for the file name, otherwise an empty string. In case inSourceCode is true then first the source filter list is considered.

Definition at line 1025 of file util.cpp.

1026{
1027 // sanity check
1028 if (name.empty()) return "";
1029
1030 StringVector filterSrcList = Config_getList(FILTER_SOURCE_PATTERNS);
1031 StringVector filterList = Config_getList(FILTER_PATTERNS);
1032
1033 DString filterName;
1034 bool found=false;
1035 if (isSourceCode && !filterSrcList.empty())
1036 { // first look for source filter pattern list
1037 filterName = getFilterFromList(name,filterSrcList,found);
1038 }
1039 if (!found && filterName.empty())
1040 { // then look for filter pattern list
1041 filterName = getFilterFromList(name,filterList,found);
1042 }
1043 if (!found)
1044 { // then use the generic input filter
1045 return Config_getString(INPUT_FILTER);
1046 }
1047 else
1048 {
1049 /* remove surrounding double quotes */
1050 if (filterName.length()>=2 && filterName[0]=='"' && filterName[static_cast<int>(filterName.length())-1]=='"')
1051 {
1052 filterName = filterName.mid(1,filterName.length()-2);
1053 }
1054 return filterName;
1055 }
1056}
static DString getFilterFromList(const DString &name, const StringVector &filterList, bool &found)
Definition util.cpp:990

References Config_getList, Config_getString, DString::empty(), getFilterFromList(), DString::length(), and DString::mid().

Referenced by FilterCache::getFileContents(), CodeFragmentManager::parseCodeFragment(), readCodeFragment(), readInputFile(), and FileDefImpl::writeSourceBody().

◆ getFileNameExtension()

◆ getLanguageFromCodeLang()

SrcLangExt getLanguageFromCodeLang ( DString & fileName)

Routine to handle the language attribute of the \code command.

Definition at line 4195 of file util.cpp.

4196{
4197 // try the extension
4198 auto lang = getLanguageFromFileName(fileName, SrcLangExt::Unknown);
4199 if (lang == SrcLangExt::Unknown)
4200 {
4201 // try the language names
4202 DString langName = fileName.lower();
4203 if (langName.at(0)=='.') langName = langName.mid(1);
4204 auto it = std::find_if(g_lang2extMap.begin(),g_lang2extMap.end(),
4205 [&langName](const auto &info) { return info.langName==langName; });
4206 if (it != g_lang2extMap.end())
4207 {
4208 lang = it->parserId;
4209 fileName = it->defExt;
4210 }
4211 else // default to C++
4212 {
4213 return SrcLangExt::Cpp;
4214 }
4215 }
4216 return lang;
4217}
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4177
static std::vector< Lang2ExtMap > g_lang2extMap
Definition util.cpp:4048

References DString::at(), g_lang2extMap, getLanguageFromFileName(), DString::lower(), and DString::mid().

Referenced by DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), ManDocVisitor::operator()(), RTFDocVisitor::operator()(), and XmlDocVisitor::operator()().

◆ getLanguageFromFileName()

SrcLangExt getLanguageFromFileName ( const DString & fileName,
SrcLangExt defLang = SrcLangExt::Cpp )

Definition at line 4177 of file util.cpp.

4178{
4179 FileInfo fi(fileName.str());
4180 // we need only the part after the last ".", newer implementations of FileInfo have 'suffix()' for this.
4181 DString extName = DString(fi.extension(false)).lower();
4182 if (extName.empty()) extName=".no_extension";
4183 if (extName.at(0)!='.') extName.prepend(".");
4184 auto it = g_extLookup.find(extName.str());
4185 if (it!=g_extLookup.end()) // listed extension
4186 {
4187 //printf("getLanguageFromFileName(%s)=%x\n",qPrint(fi.extension()),*pVal);
4188 return it->second;
4189 }
4190 //printf("getLanguageFromFileName(%s) not found!\n",qPrint(fileName));
4191 return defLang; // not listed => assume C-ish language.
4192}
static std::unordered_map< std::string, SrcLangExt > g_extLookup
Definition util.cpp:4038

References DString::at(), DString::empty(), FileInfo::extension(), g_extLookup, DString::lower(), DString::prepend(), and DString::str().

Referenced by MemberDefImpl::_writeMultiLineInitializer(), ClassDefImpl::ClassDefImpl(), convertCppComments(), DocRef::DocRef(), FileDefImpl::FileDefImpl(), generateExampleDocs(), getLanguageFromCodeLang(), EntryType::guessSection(), FileDefImpl::isDocumentationFile(), COutlineParser::needsPreprocessing(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), ManDocVisitor::operator()(), ManDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), CodeFragmentManager::parseCodeFragment(), parseFilesMultiThreading(), parseFilesSingleThreading(), parseMain(), Markdown::Private::processLink(), readCodeFragment(), setContext(), setFileName(), validatingParseDoc(), and writeXMLCodeBlock().

◆ getLanguageSpecificSeparator()

DString getLanguageSpecificSeparator ( SrcLangExt lang,
bool classScope = false )

Returns the scope separator to use given the programming language lang

Definition at line 4642 of file util.cpp.

4643{
4644 if (lang==SrcLangExt::Java || lang==SrcLangExt::CSharp || lang==SrcLangExt::VHDL || lang==SrcLangExt::Python)
4645 {
4646 return ".";
4647 }
4648 else if (lang==SrcLangExt::PHP && !classScope)
4649 {
4650 return "\\";
4651 }
4652 else
4653 {
4654 return "::";
4655 }
4656}

Referenced by DefinitionImpl::_writeSourceRefList(), addGlobalFunction(), MemberDefImpl::addListReference(), addMethodToClass(), addVariableToFile(), MemberDefImpl::displayDefinition(), DefinitionAliasImpl::init(), linkToText(), makeDisplayName(), makeDisplayName(), makeQualifiedNameWithTemplateParameters(), ClassDefImpl::mergeMembersFromBaseClasses(), MemberDefImpl::qualifiedName(), SearchIndex::setCurrentDoc(), validatingParseDoc(), MemberDefImpl::warnIfUndocumented(), writeAlphabeticalClassList(), MemberDefImpl::writeDeclaration(), writeDefArgumentList(), MemberDefImpl::writeDocumentation(), writeJavasScriptSearchDataPage(), MemberDefImpl::writeLink(), and writeMemberReference().

◆ getPrefixIndex()

int getPrefixIndex ( const DString & name)

Returns the character index within name of the first prefix in Config_getList(IGNORE_PREFIX) that matches name at the left hand side, or zero if no match was found

Definition at line 2660 of file util.cpp.

2661{
2662 if (name.empty()) return 0;
2663 int result=0;
2664 StringVector sl = Config_getList(IGNORE_PREFIX);
2665 for (const auto &s : sl)
2666 {
2667 const char *ps=s.c_str();
2668 const char *pd=name.data();
2669 int i=0;
2670 while (*ps!=0 && *pd!=0 && *ps==*pd)
2671 {
2672 ps++;
2673 pd++;
2674 i++;
2675 }
2676 if (*ps==0 && *pd!=0)
2677 {
2678 result=i;
2679 break;
2680 }
2681 }
2682 if (result<static_cast<int>(name.length())-1 && name.at(result)=='[') result++; // for e.g. [union] return u
2683 return result;
2684}

References Config_getList.

Referenced by Index::addClassMemberNameToIndex(), Index::addFileMemberNameToIndex(), Index::addModuleMemberNameToIndex(), Index::addNamespaceMemberNameToIndex(), SearchIndex::addWordRec(), parseInput(), writeAlphabeticalClassList(), and writeMemberList().

◆ getProjectId()

DString getProjectId ( )

Definition at line 5304 of file util.cpp.

5305{
5306 DString projectCookie = Config_getString(HTML_PROJECT_COOKIE);
5307 if (projectCookie.empty()) return DString();
5308 return md5str(projectCookie.view())+"_";
5309}

References Config_getString, DString::empty(), md5str(), and DString::view().

Referenced by generateJSNavTree(), HtmlGenerator::init(), and writeJavaScriptSearchIndex().

◆ getScopeFragment()

int getScopeFragment ( const DString & s,
int p,
int * l )

Returns a fragment from scope s, starting at position p.

Parameters
sthe scope name as a string.
pthe start position (0 is the first).
lthe resulting length of the fragment.
Returns
the location of the fragment, or -1 if non is found.

Definition at line 3807 of file util.cpp.

3808{
3809 int sl=static_cast<int>(s.length());
3810 int sp=p;
3811 int count=0;
3812 bool done=false;
3813 if (sp>=sl) return -1;
3814 while (sp<sl)
3815 {
3816 char c=s.at(sp);
3817 if (c==':')
3818 {
3819 sp++;
3820 p++;
3821 }
3822 else
3823 {
3824 break;
3825 }
3826 }
3827 while (sp<sl)
3828 {
3829 char c=s.at(sp);
3830 switch (c)
3831 {
3832 case ':': // found next part
3833 goto found;
3834 case '<': // skip template specifier
3835 count=1;sp++;
3836 done=false;
3837 while (sp<sl && !done)
3838 {
3839 // TODO: deal with << and >> operators!
3840 c=s.at(sp++);
3841 switch(c)
3842 {
3843 case '<': count++; break;
3844 case '>': count--; if (count==0) done=true; break;
3845 default: break;
3846 }
3847 }
3848 break;
3849 default:
3850 sp++;
3851 break;
3852 }
3853 }
3854found:
3855 *l=sp-p;
3856 //printf("getScopeFragment(%s,%d)=%s\n",qPrint(s),p,qPrint(s.mid(p,*l)));
3857 return p;
3858}

References DString::at(), and DString::length().

Referenced by buildScopeFromQualifiedName(), findScopeFromQualifiedName(), SymbolResolver::Private::followPath(), resolveTypeDef(), and stripAnonymousNamespaceScope().

◆ initDefaultExtensionMapping()

void initDefaultExtensionMapping ( )

Definition at line 4104 of file util.cpp.

4105{
4106 // NOTE: when adding an extension, also add the extension in config.xml
4107 // extension parser id
4108 updateLanguageMapping(".dox", "c");
4109 updateLanguageMapping(".txt", "c"); // see bug 760836
4110 updateLanguageMapping(".doc", "c");
4111 updateLanguageMapping(".c", "c");
4112 updateLanguageMapping(".C", "c");
4113 updateLanguageMapping(".cc", "c");
4114 updateLanguageMapping(".CC", "c");
4115 updateLanguageMapping(".cxx", "c");
4116 updateLanguageMapping(".cpp", "c");
4117 updateLanguageMapping(".c++", "c");
4118 updateLanguageMapping(".cxxm", "c"); // C++20 modules
4119 updateLanguageMapping(".cppm", "c"); // C++20 modules
4120 updateLanguageMapping(".ccm", "c"); // C++20 modules
4121 updateLanguageMapping(".c++m", "c"); // C++20 modules
4122 updateLanguageMapping(".ii", "c");
4123 updateLanguageMapping(".ixx", "c");
4124 updateLanguageMapping(".ipp", "c");
4125 updateLanguageMapping(".i++", "c");
4126 updateLanguageMapping(".inl", "c");
4127 updateLanguageMapping(".h", "c");
4128 updateLanguageMapping(".H", "c");
4129 updateLanguageMapping(".hh", "c");
4130 updateLanguageMapping(".HH", "c");
4131 updateLanguageMapping(".hxx", "c");
4132 updateLanguageMapping(".hpp", "c");
4133 updateLanguageMapping(".h++", "c");
4134 updateLanguageMapping(".idl", "idl");
4135 updateLanguageMapping(".ddl", "idl");
4136 updateLanguageMapping(".odl", "idl");
4137 updateLanguageMapping(".java", "java");
4138 //updateLanguageMapping(".as", "javascript"); // not officially supported
4139 //updateLanguageMapping(".js", "javascript"); // not officially supported
4140 updateLanguageMapping(".cs", "csharp");
4141 updateLanguageMapping(".d", "d");
4142 updateLanguageMapping(".php", "php");
4143 updateLanguageMapping(".php4", "php");
4144 updateLanguageMapping(".php5", "php");
4145 updateLanguageMapping(".inc", "php");
4146 updateLanguageMapping(".phtml", "php");
4147 updateLanguageMapping(".m", "objective-c");
4148 updateLanguageMapping(".M", "objective-c");
4149 updateLanguageMapping(".mm", "c"); // see bug746361
4150 updateLanguageMapping(".py", "python");
4151 updateLanguageMapping(".pyw", "python");
4152 updateLanguageMapping(".f", "fortran");
4153 updateLanguageMapping(".for", "fortran");
4154 updateLanguageMapping(".f90", "fortran");
4155 updateLanguageMapping(".f95", "fortran");
4156 updateLanguageMapping(".f03", "fortran");
4157 updateLanguageMapping(".f08", "fortran");
4158 updateLanguageMapping(".f18", "fortran");
4159 updateLanguageMapping(".vhd", "vhdl");
4160 updateLanguageMapping(".vhdl", "vhdl");
4161 updateLanguageMapping(".ucf", "vhdl");
4162 updateLanguageMapping(".qsf", "vhdl");
4163 updateLanguageMapping(".md", "md");
4164 updateLanguageMapping(".markdown", "md");
4165 updateLanguageMapping(".ice", "slice");
4166 updateLanguageMapping(".l", "lex");
4167 updateLanguageMapping(".doxygen_lex_c", "c"); // this is a placeholder so we can map initializations
4168 // in the lex scanning to cpp
4169}

References updateLanguageMapping().

Referenced by initDoxygen().

◆ inlineArgListToDoc()

DString inlineArgListToDoc ( const ArgumentList & al)

Returns a documentation string combining the inline documentation for each parameter in the list al.

Definition at line 4878 of file util.cpp.

4879{
4880 DString paramDocs;
4881 if (al.hasDocumentation(true))
4882 {
4883 for (const Argument &a : al)
4884 {
4885 if (a.hasDocumentation(true))
4886 {
4887 DString docsWithoutDir = a.docs;
4888 DString direction = extractDirection(docsWithoutDir);
4889 DString name = a.name;
4890 if (name.empty())
4891 {
4892 name = "-";
4893 }
4894 paramDocs+=" \\ilinebr @param"+direction+" "+name+" "+docsWithoutDir;
4895 }
4896 }
4897 }
4898 return paramDocs;
4899}
bool hasDocumentation(bool allowEmptyNames=false) const
Definition arguments.cpp:26
static DString extractDirection(DString &docs)
Strip the direction part from docs and return it as a string in canonical form.
Definition util.cpp:4842

References extractDirection(), and ArgumentList::hasDocumentation().

Referenced by DocParser::processCopyDoc(), and MemberDefImpl::writeDocumentation().

◆ inlineTemplateArgListToDoc()

DString inlineTemplateArgListToDoc ( const ArgumentList & al)

Returns a documentation string combining the inline documentation for each template parameter in the list al.

Definition at line 837 of file util.cpp.

838{
839 DString paramDocs;
841 {
842 for (const Argument &a : al)
843 {
844 if (!a.docs.empty())
845 {
846 if (!a.name.empty())
847 {
848 paramDocs+=" \\ilinebr @tparam "+a.name+" "+a.docs;
849 }
850 else if (!a.type.empty())
851 {
852 DString type = a.type;
853 type.stripPrefix("class ");
854 type.stripPrefix("typename ");
855 type = type.stripWhiteSpace();
856 paramDocs+=" \\ilinebr @tparam "+type+" "+a.docs;
857 }
858 }
859 }
860 }
861 return paramDocs;
862}
bool hasTemplateDocumentation() const
Definition arguments.cpp:34
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
bool stripPrefix(const DString &prefix)
Definition dstring.h:290

References ArgumentList::hasTemplateDocumentation(), DString::stripPrefix(), and DString::stripWhiteSpace().

Referenced by ClassDefImpl::writeDetailedDocumentationBody(), and MemberDefImpl::writeDocumentation().

◆ insertTemplateSpecifierInScope()

DString insertTemplateSpecifierInScope ( const DString & scope,
const DString & templ )

Definition at line 3085 of file util.cpp.

3086{
3087 DString result=scope;
3088 if (!templ.empty() && scope.find('<')==DString::npos)
3089 {
3090 size_t si=0, pi=0;
3091 ClassDef *cd=nullptr;
3092 while (
3093 (si=scope.find("::",pi))!=DString::npos && !getClass(scope.left(si)+templ) &&
3094 ((cd=getClass(scope.left(si)))==nullptr || cd->templateArguments().empty())
3095 )
3096 {
3097 //printf("Tried '%s'\n",qPrint((scope.left(si)+templ)));
3098 pi=si+2;
3099 }
3100 if (si==DString::npos) // not nested => append template specifier
3101 {
3102 result+=templ;
3103 }
3104 else // nested => insert template specifier before after first class name
3105 {
3106 result=scope.left(si) + templ + scope.mid(si);
3107 }
3108 }
3109 //printf("insertTemplateSpecifierInScope('%s','%s')=%s\n",
3110 // qPrint(scope),qPrint(templ),qPrint(result));
3111 return result;
3112}
bool empty() const
Definition arguments.h:100
A abstract class representing of a compound symbol.
Definition classdef.h:100
virtual const ArgumentList & templateArguments() const =0
Returns the template arguments of this class.

References ArgumentList::empty(), DString::empty(), DString::find(), getClass(), DString::left(), DString::mid(), DString::npos, and ClassDef::templateArguments().

Referenced by DotClassGraph::addClass(), generateXMLForClass(), DiagramItem::label(), ClassDefImpl::writeInheritanceGraph(), and ClassDefImpl::writeTagFile().

◆ isURL()

bool isURL ( const DString & url)

Checks whether the given url starts with a supported protocol.

Definition at line 4659 of file util.cpp.

4660{
4661 static const std::unordered_set<std::string> schemes = {
4662 "http", "https", "ftp", "ftps", "sftp", "file", "news", "irc", "ircs"
4663 };
4664 DString loc_url = url.stripWhiteSpace();
4665 size_t colonPos = loc_url.find(':');
4666 return colonPos!=DString::npos && schemes.find(loc_url.left(colonPos).str())!=schemes.end();
4667}

References DString::find(), DString::left(), DString::npos, DString::str(), and DString::stripWhiteSpace().

Referenced by correctURL(), and Markdown::Private::processLink().

◆ leftScopeMatch()

bool leftScopeMatch ( const DString & scope,
const DString & name )

Definition at line 745 of file util.cpp.

746{
747 size_t sl=scope.length();
748 size_t nl=name.length();
749 return (name==scope || // equal
750 (name.left(sl)==scope && // substring
751 nl>sl+1 && name.at(sl)==':' && name.at(sl+1)==':' // scope
752 )
753 );
754}

References DString::length().

Referenced by addClassToContext(), addConceptToContext(), buildFunctionList(), mergeScopes(), pushScope(), and resolveRef().

◆ linkToText()

DString linkToText ( SrcLangExt lang,
const DString & link,
bool ignoreDots )

Definition at line 2273 of file util.cpp.

2274{
2275 //bool optimizeOutputJava = Config_getBool(OPTIMIZE_OUTPUT_JAVA);
2276 DString result=link;
2277 if (!result.empty())
2278 {
2279 // replace # by ::
2280 result=substitute(result,"#","::");
2281 // replace . by ::
2282 if (!ignoreDots && result.find('<')==DString::npos) result=substitute(result,".","::",3);
2283 // strip leading :: prefix if present
2284 if (result.at(0)==':' && result.at(1)==':')
2285 {
2286 result=result.mid(2);
2287 }
2289 if (sep!="::")
2290 {
2291 result=substitute(result,"::",sep);
2292 }
2293 }
2294 //printf("linkToText(%s,lang=%d)=%s\n",qPrint(link),lang,qPrint(result));
2295 return result;
2296}
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4642

References DString::at(), DString::empty(), DString::find(), getLanguageSpecificSeparator(), DString::mid(), DString::npos, and substitute().

Referenced by DotCallGraph::buildGraph(), DocRef::DocRef(), DotCallGraph::DotCallGraph(), and DocParser::handleLinkedWord().

◆ mainPageHasTitle()

bool mainPageHasTitle ( )

Definition at line 4972 of file util.cpp.

4973{
4974 return Doxygen::mainPage!=nullptr && Doxygen::mainPage->hasTitle();
4975}
static std::unique_ptr< PageDef > mainPage
Definition doxygen.h:93

References Doxygen::mainPage.

Referenced by generateJSNavTree(), generateSqlite3ForPage(), and generateXMLForPage().

◆ makeBaseName()

◆ mangleCSharpGenericName()

DString mangleCSharpGenericName ( const DString & name)

Definition at line 5354 of file util.cpp.

5355{
5356 DString result;
5357 size_t p=0;
5358 size_t idx;
5359 while ((idx=name.find('<',p))!=DString::npos)
5360 {
5361 result+=name.mid(p,idx-p);
5362 // count the top level arguments of the balanced <...> group
5363 int depth=0;
5364 int count=1;
5365 size_t i=idx;
5366 for (; i<name.length(); i++)
5367 {
5368 char c=name[i];
5369 if (c=='<') depth++;
5370 else if (c=='>' && --depth==0) break;
5371 else if (c==',' && depth==1) count++;
5372 }
5373 result+="-"+DString().setNum(count)+"-g";
5374 p=i+1;
5375 }
5376 if (p<name.length()) result+=name.mid(p);
5377 return result;
5378}
DString & setNum(short n)
Definition dstring.h:552

References DString::npos, and DString::setNum().

Referenced by addClassToContext(), addEnumValuesToEnums(), addVariable(), buildFunctionList(), extractClassName(), findClassRelation(), findEnums(), SymbolResolver::resolveClass(), resolveLink(), and resolveRef().

◆ matchArguments2()

bool matchArguments2 ( const Definition * srcScope,
const FileDef * srcFileScope,
const DString & srcReturnType,
const ArgumentList * srcAl,
const Definition * dstScope,
const FileDef * dstFileScope,
const DString & dstReturnType,
const ArgumentList * dstAl,
bool checkCV,
SrcLangExt lang )

Compares two parameter lists srcAl and dstAl and returns true if they match.

Definition at line 1597 of file util.cpp.

1600{
1601 ASSERT(srcScope!=nullptr && dstScope!=nullptr);
1602
1603 AUTO_TRACE("srcScope='{}' dstScope='{}' srcArgs='{}' dstArgs='{}' checkCV={} lang={}",
1604 srcScope->name(),dstScope->name(),srcAl?argListToString(*srcAl):"",dstAl?argListToString(*dstAl):"",checkCV,lang);
1605
1606 if (srcAl==nullptr || dstAl==nullptr)
1607 {
1608 bool match = srcAl==dstAl;
1609 if (match)
1610 {
1611 MATCH
1612 return true;
1613 }
1614 else
1615 {
1616 NOMATCH
1617 return false;
1618 }
1619 }
1620
1621 // handle special case with void argument
1622 if ( srcAl->empty() && dstAl->size()==1 && dstAl->front().type=="void" )
1623 { // special case for finding match between func() and func(void)
1624 Argument a;
1625 a.type = "void";
1626 const_cast<ArgumentList*>(srcAl)->push_back(a);
1627 MATCH
1628 return true;
1629 }
1630 if ( dstAl->empty() && srcAl->size()==1 && srcAl->front().type=="void" )
1631 { // special case for finding match between func(void) and func()
1632 Argument a;
1633 a.type = "void";
1634 const_cast<ArgumentList*>(dstAl)->push_back(a);
1635 MATCH
1636 return true;
1637 }
1638
1639 if (srcAl->size() != dstAl->size())
1640 {
1641 NOMATCH
1642 return false; // different number of arguments -> no match
1643 }
1644
1645 if (checkCV)
1646 {
1647 if (srcAl->constSpecifier() != dstAl->constSpecifier())
1648 {
1649 NOMATCH
1650 return false; // one member is const, the other not -> no match
1651 }
1652 if (srcAl->volatileSpecifier() != dstAl->volatileSpecifier())
1653 {
1654 NOMATCH
1655 return false; // one member is volatile, the other not -> no match
1656 }
1657 }
1658
1659 if (srcAl->refQualifier() != dstAl->refQualifier())
1660 {
1661 NOMATCH
1662 return false; // one member is has a different ref-qualifier than the other
1663 }
1664
1665 if (srcReturnType=="auto" && dstReturnType=="auto" && srcAl->trailingReturnType()!=dstAl->trailingReturnType())
1666 {
1667 NOMATCH
1668 return false; // one member is has a different return type than the other
1669 }
1670
1671 // so far the argument list could match, so we need to compare the types of
1672 // all arguments.
1673 auto srcIt = srcAl->begin();
1674 auto dstIt = dstAl->begin();
1675 for (;srcIt!=srcAl->end() && dstIt!=dstAl->end();++srcIt,++dstIt)
1676 {
1677 Argument &srcA = const_cast<Argument&>(*srcIt);
1678 Argument &dstA = const_cast<Argument&>(*dstIt);
1679 if (!matchArgument2(srcScope,srcFileScope,srcA,
1680 dstScope,dstFileScope,dstA,
1681 lang)
1682 )
1683 {
1684 NOMATCH
1685 return false;
1686 }
1687 }
1688 MATCH
1689 return true; // all arguments match
1690}
This class represents an function or template argument list.
Definition arguments.h:66
Argument & front()
Definition arguments.h:106
size_t size() const
Definition arguments.h:101
#define MATCH
Definition util.cpp:1496
DString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:864
#define NOMATCH
Definition util.cpp:1497
static bool matchArgument2(const Definition *srcScope, const FileDef *srcFileScope, Argument &srcA, const Definition *dstScope, const FileDef *dstFileScope, Argument &dstA, SrcLangExt lang)
Definition util.cpp:1531

References argListToString(), ASSERT, AUTO_TRACE, ArgumentList::begin(), ArgumentList::constSpecifier(), ArgumentList::empty(), ArgumentList::end(), ArgumentList::front(), MATCH, matchArgument2(), Definition::name(), NOMATCH, ArgumentList::refQualifier(), ArgumentList::size(), ArgumentList::trailingReturnType(), Argument::type, and ArgumentList::volatileSpecifier().

Referenced by addMemberDocs(), addMemberFunction(), buildFunctionList(), combineDeclarationAndDefinition(), computeMemberRelationsForBaseClass(), ClassDefImpl::containsOverload(), findFriends(), findGlobalMember(), findMember(), SymbolResolver::Private::getResolvedSymbol(), GroupDefImpl::insertMember(), matchCanonicalTypes(), ClassDefImpl::mergeMembersFromBaseClasses(), transferFunctionReferences(), and transferRelatedFunctionDocumentation().

◆ matchTemplateArguments()

bool matchTemplateArguments ( const ArgumentList & srcAl,
const ArgumentList & dstAl )

Returns true if the template parameter lists srcAl and dstAl match. The lists are considered to match if they have the same number of parameters and each matching parameter in srcAl and dstAl has the same constraints (or at least one parameter has no constraints).

Definition at line 1841 of file util.cpp.

1842{
1843 AUTO_TRACE("srcAl={} dstAl={}",argListToString(srcAl),argListToString(dstAl));
1844 if (srcAl.size()!=dstAl.size()) // different number of template parameters -> overload
1845 {
1846 AUTO_TRACE_EXIT("different number of parameters");
1847 return false;
1848 }
1849 auto isUnconstraintTemplate = [](const DString &type)
1850 {
1851 return type=="typename" || type=="class" || type.startsWith("typename ") || type.startsWith("class ");
1852 };
1853 auto srcIt = srcAl.begin();
1854 auto dstIt = dstAl.begin();
1855 while (srcIt!=srcAl.end() && dstIt!=dstAl.end())
1856 {
1857 const Argument &srcA = *srcIt;
1858 const Argument &dstA = *dstIt;
1859 if ((!isUnconstraintTemplate(srcA.type) || !isUnconstraintTemplate(dstA.type)) && srcA.type!=dstA.type) // different constraints -> overload
1860 {
1861 AUTO_TRACE_EXIT("different constraints");
1862 return false;
1863 }
1864 ++srcIt;
1865 ++dstIt;
1866 }
1867 AUTO_TRACE_EXIT("same");
1868 // no overload with respect to the template parameters
1869 return true;
1870}

References argListToString(), AUTO_TRACE, AUTO_TRACE_EXIT, ArgumentList::begin(), ArgumentList::end(), ArgumentList::size(), and Argument::type.

Referenced by buildFunctionList().

◆ mergeArguments()

void mergeArguments ( ArgumentList & srcAl,
ArgumentList & dstAl,
bool forceNameOverwrite = false )

Merges the information of two parameter lists (typically a declaration and a definition). Missing information is added to either list. The name of parameter of srcAl is only overwritten if forceNameOverwrite is true.

Definition at line 1697 of file util.cpp.

1698{
1699 AUTO_TRACE("srcAl='{}',dstAl='{}',forceNameOverwrite={}",
1700 qPrint(argListToString(srcAl)),qPrint(argListToString(dstAl)),forceNameOverwrite);
1701
1702 if (srcAl.size()!=dstAl.size())
1703 {
1704 return; // invalid argument lists -> do not merge
1705 }
1706
1707 auto srcIt=srcAl.begin();
1708 auto dstIt=dstAl.begin();
1709 while (srcIt!=srcAl.end() && dstIt!=dstAl.end())
1710 {
1711 Argument &srcA = *srcIt;
1712 Argument &dstA = *dstIt;
1713
1714 AUTO_TRACE_ADD("before merge: src=[type='{}',name='{}',def='{}'] dst=[type='{}',name='{}',def='{}']",
1715 srcA.type,srcA.name,srcA.defval,
1716 dstA.type,dstA.name,dstA.defval);
1717 if (srcA.defval.empty() && !dstA.defval.empty())
1718 {
1719 //printf("Defval changing '%s'->'%s'\n",qPrint(srcA.defval),qPrint(dstA.defval));
1720 srcA.defval=dstA.defval;
1721 }
1722 else if (!srcA.defval.empty() && dstA.defval.empty())
1723 {
1724 //printf("Defval changing '%s'->'%s'\n",qPrint(dstA.defval),qPrint(srcA.defval));
1725 dstA.defval=srcA.defval;
1726 }
1727
1728 // fix wrongly detected const or volatile specifiers before merging.
1729 // example: "const A *const" is detected as type="const A *" name="const"
1730 if (srcA.name=="const" || srcA.name=="volatile")
1731 {
1732 srcA.type+=" "+srcA.name;
1733 srcA.name.clear();
1734 }
1735 if (dstA.name=="const" || dstA.name=="volatile")
1736 {
1737 dstA.type+=" "+dstA.name;
1738 dstA.name.clear();
1739 }
1740
1741 if (srcA.type==dstA.type)
1742 {
1743 //printf("1. merging %s:%s <-> %s:%s\n",qPrint(srcA.type),qPrint(srcA.name),qPrint(dstA.type),qPrint(dstA.name));
1744 if (srcA.name.empty() && !dstA.name.empty())
1745 {
1746 //printf("type: '%s':='%s'\n",qPrint(srcA.type),qPrint(dstA.type));
1747 //printf("name: '%s':='%s'\n",qPrint(srcA.name),qPrint(dstA.name));
1748 srcA.type = dstA.type;
1749 srcA.name = dstA.name;
1750 }
1751 else if (!srcA.name.empty() && dstA.name.empty())
1752 {
1753 //printf("type: '%s':='%s'\n",qPrint(dstA.type),qPrint(srcA.type));
1754 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1755 dstA.type = srcA.type;
1756 dstA.name = srcA.name;
1757 }
1758 else if (!srcA.name.empty() && !dstA.name.empty())
1759 {
1760 //printf("srcA.name=%s dstA.name=%s\n",qPrint(srcA.name),qPrint(dstA.name));
1761 if (forceNameOverwrite)
1762 {
1763 srcA.name = dstA.name;
1764 }
1765 else
1766 {
1767 if (srcA.docs.empty() && !dstA.docs.empty())
1768 {
1769 srcA.name = dstA.name;
1770 }
1771 else if (!srcA.docs.empty() && dstA.docs.empty())
1772 {
1773 dstA.name = srcA.name;
1774 }
1775 }
1776 }
1777 }
1778 else
1779 {
1780 //printf("2. merging '%s':'%s' <-> '%s':'%s'\n",qPrint(srcA.type),qPrint(srcA.name),qPrint(dstA.type),qPrint(dstA.name));
1781 srcA.type=srcA.type.stripWhiteSpace();
1782 dstA.type=dstA.type.stripWhiteSpace();
1783 if (srcA.type+" "+srcA.name==dstA.type) // "unsigned long:int" <-> "unsigned long int:bla"
1784 {
1785 srcA.type+=" "+srcA.name;
1786 srcA.name=dstA.name;
1787 }
1788 else if (dstA.type+" "+dstA.name==srcA.type) // "unsigned long int bla" <-> "unsigned long int"
1789 {
1790 dstA.type+=" "+dstA.name;
1791 dstA.name=srcA.name;
1792 }
1793 else if (srcA.name.empty() && !dstA.name.empty())
1794 {
1795 srcA.name = dstA.name;
1796 }
1797 else if (dstA.name.empty() && !srcA.name.empty())
1798 {
1799 dstA.name = srcA.name;
1800 }
1801 }
1802 size_t i1=srcA.type.find("::"),
1803 i2=dstA.type.find("::"),
1804 j1=srcA.type.length()-i1-2,
1805 j2=dstA.type.length()-i2-2;
1806 if (i1!=DString::npos && i2==DString::npos && srcA.type.right(j1)==dstA.type)
1807 {
1808 //printf("type: '%s':='%s'\n",qPrint(dstA.type),qPrint(srcA.type));
1809 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1810 dstA.type = srcA.type.left(i1+2)+dstA.type;
1811 dstA.name = srcA.name;
1812 }
1813 else if (i1==DString::npos && i2!=DString::npos && dstA.type.right(j2)==srcA.type)
1814 {
1815 //printf("type: '%s':='%s'\n",qPrint(srcA.type),qPrint(dstA.type));
1816 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1817 srcA.type = dstA.type.left(i2+2)+srcA.type;
1818 srcA.name = dstA.name;
1819 }
1820 if (srcA.docs.empty() && !dstA.docs.empty())
1821 {
1822 srcA.docs = dstA.docs;
1823 }
1824 else if (dstA.docs.empty() && !srcA.docs.empty())
1825 {
1826 dstA.docs = srcA.docs;
1827 }
1828 //printf("Merge argument '%s|%s' '%s|%s'\n",
1829 // qPrint(srcA.type), qPrint(srcA.name),
1830 // qPrint(dstA.type), qPrint(dstA.name));
1831 ++srcIt;
1832 ++dstIt;
1833 AUTO_TRACE_ADD("after merge: src=[type='{}',name='{}',def='{}'] dst=[type='{}',name='{}',def='{}']",
1834 srcA.type,srcA.name,srcA.defval,
1835 dstA.type,dstA.name,dstA.defval);
1836 }
1837}
DString docs
Definition arguments.h:48
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54

References argListToString(), AUTO_TRACE, AUTO_TRACE_ADD, ArgumentList::begin(), DString::clear(), Argument::defval, Argument::docs, DString::empty(), ArgumentList::end(), DString::find(), DString::left(), DString::length(), Argument::name, DString::npos, qPrint(), DString::right(), ArgumentList::size(), DString::stripWhiteSpace(), and Argument::type.

Referenced by addMemberDocs(), buildFunctionList(), and findFriends().

◆ mergeScopes()

DString mergeScopes ( const DString & leftScope,
const DString & rightScope )

Merges two scope parts together. The parts may (partially) overlap. Example1: A::B and B::C will result in A::B::C
Example2: A and B will be A::B
Example3: A::B and B will be A::B

Parameters
leftScopethe left hand part of the scope.
rightScopethe right hand part of the scope.
Returns
the merged scope.

Definition at line 3762 of file util.cpp.

3763{
3764 AUTO_TRACE("leftScope='{}' rightScope='{}'",leftScope,rightScope);
3765 // case leftScope=="A" rightScope=="A::B" => result = "A::B"
3766 if (leftScopeMatch(leftScope,rightScope))
3767 {
3768 AUTO_TRACE_EXIT("case1={}",rightScope);
3769 return rightScope;
3770 }
3771 DString result;
3772 size_t i=0,p=leftScope.length();
3773
3774 // case leftScope=="A::B" rightScope=="B::C" => result = "A::B::C"
3775 // case leftScope=="A::B" rightScope=="B" => result = "A::B"
3776 bool found=false;
3777 while ((i=leftScope.rfind("::",p))!=DString::npos && i>0)
3778 {
3779 if (leftScopeMatch(rightScope,leftScope.mid(i+2)))
3780 {
3781 result = leftScope.left(i+2)+rightScope;
3782 found=true;
3783 }
3784 p=i-1;
3785 }
3786 if (found)
3787 {
3788 AUTO_TRACE_EXIT("case2={}",result);
3789 return result;
3790 }
3791
3792 // case leftScope=="A" rightScope=="B" => result = "A::B"
3793 result=leftScope;
3794 if (!result.empty() && !rightScope.empty()) result+="::";
3795 result+=rightScope;
3796 AUTO_TRACE_EXIT("case3={}",result);
3797 return result;
3798}
bool leftScopeMatch(const DString &scope, const DString &name)
Definition util.cpp:745

References AUTO_TRACE, AUTO_TRACE_EXIT, DString::empty(), DString::left(), leftScopeMatch(), DString::length(), DString::mid(), DString::npos, and DString::rfind().

Referenced by addEnumValuesToEnums(), addVariable(), findEnums(), findMember(), and stripTemplateSpecifiersFromScope().

◆ normalizeNonTemplateArgumentsInString()

DString normalizeNonTemplateArgumentsInString ( const DString & name,
const Definition * context,
const ArgumentList & formalArgs )

Returns a representation of name where all known types have been normalized to their canonical form. The normalization is done in the context of context and using the formal arguments in formalArgs.

Definition at line 3474 of file util.cpp.

3478{
3479 // skip until <
3480 size_t p=name.find('<');
3481 if (p==DString::npos) return name;
3482 p++;
3483 DString result = name.left(p);
3484
3485 std::string s = name.mid(p).str();
3486 static const reg::Ex re(R"([\a:][\w:]*)");
3487 reg::Iterator it(s,re);
3489 size_t pi=0;
3490 // for each identifier in the template part (e.g. B<T> -> T)
3491 for (; it!=end ; ++it)
3492 {
3493 const auto &match = *it;
3494 size_t i = match.position();
3495 size_t l = match.length();
3496 result += s.substr(pi,i-pi);
3497 DString n(match.str());
3498 bool found=false;
3499 for (const Argument &formArg : formalArgs)
3500 {
3501 if (formArg.name == n)
3502 {
3503 found=true;
3504 break;
3505 }
3506 }
3507 if (!found)
3508 {
3509 // try to resolve the type
3510 SymbolResolver resolver;
3511 const ClassDef *cd = resolver.resolveClass(context,n);
3512 if (cd)
3513 {
3514 result+=cd->name();
3515 }
3516 else
3517 {
3518 result+=n;
3519 }
3520 }
3521 else
3522 {
3523 result+=n;
3524 }
3525 pi=i+l;
3526 }
3527 result+=s.substr(pi);
3528 //printf("normalizeNonTemplateArgumentInString(%s)=%s\n",qPrint(name),qPrint(result));
3529 return removeRedundantWhiteSpace(result);
3530}
DString substr(size_t pos=0, size_t count=npos) const
Returns a substring of length count starting at pos.
Definition dstring.h:223
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.

References end(), Definition::name(), DString::npos, removeRedundantWhiteSpace(), SymbolResolver::resolveClass(), and DString::substr().

Referenced by findUsedClassesForClass().

◆ openOutputFile()

bool openOutputFile ( const DString & outFile,
std::ofstream & f )

Helper to open an output search f for writing. If the file already exists it will be renamed to .bak first. If outFile is "-" then the output will be written to standard output.

Definition at line 4999 of file util.cpp.

5000{
5001 ASSERT(!f.is_open());
5002 bool fileOpened=false;
5003 bool writeToStdout=outFile=="-";
5004 if (writeToStdout) // write to stdout
5005 {
5006 f.basic_ios<char>::rdbuf(std::cout.rdbuf());
5007 fileOpened = true;
5008 }
5009 else // write to file
5010 {
5011 FileInfo fi(outFile.str());
5012 if (fi.exists()) // create a backup
5013 {
5014 Dir dir;
5015 FileInfo backup(fi.filePath()+".bak");
5016 if (backup.exists()) // remove existing backup
5017 dir.remove(backup.filePath());
5018 dir.rename(fi.filePath(),fi.filePath()+".bak");
5019 }
5020 f = Portable::openOutputStream(outFile);
5021 fileOpened = f.is_open();
5022 }
5023 return fileOpened;
5024}
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition dir.cpp:326
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:679

References ASSERT, FileInfo::exists(), FileInfo::filePath(), Portable::openOutputStream(), Dir::remove(), Dir::rename(), and DString::str().

Referenced by compareDoxyfile(), generateConfigFile(), readConfiguration(), and writeDefaultLayoutFile().

◆ projectLogoFile()

DString projectLogoFile ( )

Definition at line 2589 of file util.cpp.

2590{
2591 DString projectLogo = Config_getString(PROJECT_LOGO);
2592 if (!projectLogo.empty())
2593 {
2594 // check for optional width= and height= specifier
2595 if (size_t wi = projectLogo.find(" width="); wi!=DString::npos) // and strip them
2596 {
2597 projectLogo = projectLogo.left(wi);
2598 }
2599 if (size_t hi = projectLogo.find(" height="); hi!=DString::npos)
2600 {
2601 projectLogo = projectLogo.left(hi);
2602 }
2603 }
2604 //printf("projectlogo='%s'\n",qPrint(projectLogo));
2605 return projectLogo;
2606}

References Config_getString, DString::empty(), DString::find(), DString::left(), and DString::npos.

Referenced by copyLogo(), substituteHtmlKeywords(), and substituteLatexKeywords().

◆ projectLogoSize()

DString projectLogoSize ( )

Definition at line 2608 of file util.cpp.

2609{
2610 DString sizeVal;
2611 DString projectLogo = Config_getString(PROJECT_LOGO);
2612 if (!projectLogo.empty())
2613 {
2614 auto extractDimension = [&projectLogo](const char *startMarker,size_t startPos,size_t endPos) -> DString
2615 {
2616 DString result = projectLogo.mid(startPos,endPos-startPos).stripWhiteSpace().quoted();
2617 if (result.length()>=2 && result.at(0)!='"' && result.at(result.length()-1)!='"')
2618 {
2619 result="\""+result+"\"";
2620 }
2621 result.prepend(startMarker);
2622 return result;
2623 };
2624 // check for optional width= and height= specifier
2625 size_t wi = projectLogo.find(" width=");
2626 size_t hi = projectLogo.find(" height=");
2627 if (wi!=DString::npos && hi!=DString::npos)
2628 {
2629 if (wi<hi) // "... width=x height=y..."
2630 {
2631 sizeVal = extractDimension(" width=", wi+7, hi) + " "
2632 + extractDimension(" height=", hi+8, projectLogo.length());
2633 }
2634 else // "... height=y width=x..."
2635 {
2636 sizeVal = extractDimension(" height=", hi+8, wi) + " "
2637 + extractDimension(" width=", wi+7, projectLogo.length());
2638 }
2639 }
2640 else if (wi!=DString::npos) // ... width=x..."
2641 {
2642 sizeVal = extractDimension(" width=", wi+7, projectLogo.length());
2643 }
2644 else if (hi!=DString::npos) // ... height=x..."
2645 {
2646 sizeVal = extractDimension(" height=", hi+8, projectLogo.length());
2647 }
2648 }
2649 //printf("projectsize='%s'\n",qPrint(sizeVal));
2650 return sizeVal;
2651}
DString quoted() const
Definition dstring.h:352

References DString::at(), Config_getString, DString::empty(), DString::find(), DString::length(), DString::mid(), DString::npos, DString::prepend(), DString::quoted(), and DString::stripWhiteSpace().

Referenced by substituteHtmlKeywords(), and substituteLatexKeywords().

◆ protectionLevelVisible()

bool protectionLevelVisible ( Protection prot)

Definition at line 4684 of file util.cpp.

4685{
4686 bool extractPrivate = Config_getBool(EXTRACT_PRIVATE);
4687 bool extractPackage = Config_getBool(EXTRACT_PACKAGE);
4688
4689 return (prot!=Protection::Private && prot!=Protection::Package) ||
4690 (prot==Protection::Private && extractPrivate) ||
4691 (prot==Protection::Package && extractPackage);
4692}

References Config_getBool.

Referenced by MemberDefImpl::_computeLinkableInProject(), addClassAndNestedClasses(), computeClassRelations(), MemberDefImpl::hasDetailedDescription(), ClassDefImpl::internalInsertMember(), MemberDefImpl::isBriefSectionVisible(), ClassDefImpl::isLinkableInProject(), ClassDefImpl::isVisibleInHierarchy(), MemberDefImpl::warnIfUndocumented(), MemberDefImpl::writeDeclaration(), ClassDefImpl::writeDocumentationForInnerClasses(), ClassDefImpl::writeMemberList(), and ClassDefImpl::writeTagFile().

◆ readInputFile()

bool readInputFile ( const DString & fileName,
std::string & contents,
const ReadInputFileOptions & options = ReadInputFileOptions() )

read a file name fileName and optionally filter and transcode it

Definition at line 4383 of file util.cpp.

4384{
4385 // try to open file
4386 FileInfo fi(fileName.str());
4387 if (!fi.exists()) return false;
4388 DString filterName = getFileFilter(fileName,options.isSourceCode());
4389 if (filterName.empty() || !options.filter())
4390 {
4391 std::ifstream f = Portable::openInputStream(fileName,true);
4392 if (!f.is_open())
4393 {
4394 err("could not open file {}\n",fileName);
4395 return false;
4396 }
4397 // read the file
4398 auto fileSize = fi.size();
4399 contents.resize(fileSize);
4400 f.read(contents.data(),fileSize);
4401 if (f.fail())
4402 {
4403 err("problems while reading file {}\n",fileName);
4404 return false;
4405 }
4406 }
4407 else
4408 {
4409 DString cmd=filterName+" \""+fileName+"\"";
4410 Debug::print(Debug::ExtCmd,0,"Executing popen(`{}`)\n",cmd);
4411 FILE *f=Portable::popen(cmd,"r");
4412 if (!f)
4413 {
4414 err("could not execute filter {}\n",filterName);
4415 return false;
4416 }
4417 const int bufSize=4096;
4418 char buf[bufSize];
4419 int numRead = 0;
4420 while ((numRead=static_cast<int>(fread(buf,1,bufSize,f)))>0)
4421 {
4422 //printf(">>>>>>>>Reading %d bytes\n",numRead);
4423 contents.append(buf,numRead);
4424 }
4426 Debug::print(Debug::FilterOutput, 0, "Filter output\n");
4427 Debug::print(Debug::FilterOutput,0,"-------------\n{}\n-------------\n",contents);
4428 }
4429 if (options.binary())
4430 {
4431 return true;
4432 }
4433
4434 if (contents.size()>=2 &&
4435 static_cast<uint8_t>(contents[0])==0xFF &&
4436 static_cast<uint8_t>(contents[1])==0xFE // Little endian BOM
4437 ) // UCS-2LE encoded file
4438 {
4439 transcodeCharacterBuffer(fileName,contents,"UCS-2LE","UTF-8");
4440 }
4441 else if (contents.size()>=2 &&
4442 static_cast<uint8_t>(contents[0])==0xFE &&
4443 static_cast<uint8_t>(contents[1])==0xFF // big endian BOM
4444 ) // UCS-2BE encoded file
4445 {
4446 transcodeCharacterBuffer(fileName,contents,"UCS-2BE","UTF-8");
4447 }
4448 else if (contents.size()>=3 &&
4449 static_cast<uint8_t>(contents[0])==0xEF &&
4450 static_cast<uint8_t>(contents[1])==0xBB &&
4451 static_cast<uint8_t>(contents[2])==0xBF
4452 ) // UTF-8 encoded file
4453 {
4454 contents.erase(0,3); // remove UTF-8 BOM: no translation needed
4455 }
4456 else // transcode according to the INPUT_ENCODING setting
4457 {
4458 // do character transcoding if needed.
4459 transcodeCharacterBuffer(fileName,contents,getEncoding(fi),"UTF-8");
4460 }
4461
4462 filterCRLF(contents);
4463 return true;
4464}
@ FilterOutput
Definition debug.h:39
@ ExtCmd
Definition debug.h:37
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
FILE * popen(const DString &name, const DString &type)
Definition portable.cpp:495
std::ifstream openInputStream(const DString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:690
int pclose(FILE *stream)
Definition portable.cpp:504
bool binary() const
Definition util.h:64
bool filter() const
Definition util.h:62
bool isSourceCode() const
Definition util.h:63
static void filterCRLF(std::string &contents)
Definition util.cpp:964
DString getFileFilter(const DString &name, bool isSourceCode)
Definition util.cpp:1025
static void transcodeCharacterBuffer(const DString &fileName, std::string &contents, const DString &inputEncoding, const DString &outputEncoding)
Definition util.cpp:4347
DString getEncoding(const FileInfo &fi)
Definition util.cpp:4490

References ReadInputFileOptions::binary(), DString::empty(), err, FileInfo::exists(), Debug::ExtCmd, ReadInputFileOptions::filter(), filterCRLF(), Debug::FilterOutput, getEncoding(), getFileFilter(), ReadInputFileOptions::isSourceCode(), Portable::openInputStream(), Portable::pclose(), Portable::popen(), Debug::print(), FileInfo::size(), DString::str(), and transcodeCharacterBuffer().

Referenced by checkAndOpenFile(), fileToString(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), parseFile(), parseInput(), readIncludeFile(), DocbookDocVisitor::startMermaidFile(), LatexDocVisitor::startMermaidFile(), DocbookDocVisitor::startPlantUmlFile(), and LatexDocVisitor::startPlantUmlFile().

◆ relativePathToRoot()

DString relativePathToRoot ( const DString & name)

Definition at line 2921 of file util.cpp.

2922{
2923 DString result;
2924 if (Config_getBool(CREATE_SUBDIRS))
2925 {
2926 if (name.empty())
2927 {
2928 return REL_PATH_TO_ROOT;
2929 }
2930 else if (size_t i = name.rfind('/'); i!=DString::npos)
2931 {
2932 result=REL_PATH_TO_ROOT;
2933 }
2934 }
2935 return result;
2936}
#define REL_PATH_TO_ROOT
Definition util.cpp:78

References Config_getBool, DString::npos, and REL_PATH_TO_ROOT.

Referenced by generateBriefDoc(), DocbookGenerator::startFile(), HtmlGenerator::startFile(), LatexGenerator::startFile(), RTFGenerator::startFile(), and validatingParseDoc().

◆ removeAnonymousScopes()

DString removeAnonymousScopes ( const DString & str)

Removes all anonymous scopes from string s Possible examples:

   "bla::@10::blep"      => "bla::blep"
   "bla::@10::@11::blep" => "bla::blep"
   "@10::blep"           => "blep"
   " @10::blep"          => "blep"
   "@9::@10::blep"       => "blep"
   "bla::@1"             => "bla"
   "bla::@1::@2"         => "bla"
   "bla @1"              => "bla"

Definition at line 98 of file util.cpp.

99{
100 std::string result;
101 if (str.empty()) return result;
102
103 // helper to check if the found delimiter starts with a colon
104 auto startsWithColon = [](const std::string &del)
105 {
106 for (size_t i=0;i<del.size();i++)
107 {
108 if (del[i]=='@') return false;
109 else if (del[i]==':') return true;
110 }
111 return false;
112 };
113
114 // helper to check if the found delimiter ends with a colon
115 auto endsWithColon = [](const std::string &del)
116 {
117 for (int i=static_cast<int>(del.size())-1;i>=0;i--)
118 {
119 if (del[i]=='@') return false;
120 else if (del[i]==':') return true;
121 }
122 return false;
123 };
124
125 static const reg::Ex re(R"([\s:]*@\d+[\s:]*)");
126 std::string s = str.str();
127 reg::Iterator iter(s,re);
129 size_t p=0;
130 size_t sl=s.length();
131 bool needsSeparator=false;
132 for ( ; iter!=end ; ++iter)
133 {
134 const auto &match = *iter;
135 size_t i = match.position();
136 if (i>p) // add non-matching prefix
137 {
138 if (needsSeparator) result+="::";
139 needsSeparator=false;
140 result+=s.substr(p,i-p);
141 }
142 std::string delim = match.str();
143 needsSeparator = needsSeparator || (startsWithColon(delim) && endsWithColon(delim));
144 p = match.position()+match.length();
145 }
146 if (p<sl) // add trailing remainder
147 {
148 if (needsSeparator) result+="::";
149 result+=s.substr(p);
150 }
151 return result;
152}

References DString::empty(), end(), and DString::str().

Referenced by createTagLessInstance(), MemberDefImpl::displayDefinition(), generateClassMemberLink(), ClassDefImpl::internalInsertMember(), makeDisplayName(), makeDisplayName(), simplifyTypeForTable(), MemberDefImpl::writeDeclaration(), and MemberDefImpl::writeDocumentation().

◆ removeRedundantWhiteSpace()

DString removeRedundantWhiteSpace ( const DString & s)

Definition at line 427 of file util.cpp.

428{
429 bool cliSupport = Config_getBool(CPP_CLI_SUPPORT);
430 bool vhdl = Config_getBool(OPTIMIZE_OUTPUT_VHDL);
431
432 if (s.empty() || vhdl) return s;
433
434 // We use a static character array to
435 // improve the performance of this function
436 // and thread_local is needed to make it multi-thread safe
437 static THREAD_LOCAL std::vector<char> growBuf;
438 if (s.length()*3+1 > growBuf.size()) // For input character we produce at most 3 output characters,
439 {
440 growBuf.resize(s.length()*3+1); // add 1 for 0-terminator
441 }
442
443 const char *src=s.data();
444 char *dst=growBuf.data();
445
446 size_t i=0;
447 size_t l=s.length();
448 size_t csp=0;
449 size_t vosp=0;
450 size_t vsp=0;
451 size_t osp=0;
452 size_t ssp=0;
453 char pc=0;
454 // skip leading whitespace
455 while (i<l && isspace(static_cast<uint8_t>(src[i])))
456 {
457 i++;
458 }
459 for (;i<l;i++)
460 {
461 char c=src[i];
462 char nc=i+1<l ? src[i+1] : ' ';
463
464 auto searchForKeyword = [&](const char *kw,size_t &matchLen,size_t totalLen)
465 {
466 if (matchLen<=totalLen && c==kw[matchLen] && // character matches substring kw
467 (matchLen>0 || // inside search string
468 i==0 || // if it is the first character
469 !isId(pc) // the previous may not be a digit
470 )
471 )
472 matchLen++;
473 else // reset counter
474 matchLen=0;
475 };
476 searchForKeyword(constScope, csp, 5); // keyword: const
477 searchForKeyword(volatileScope, vosp, 8); // keyword: volatile
478 searchForKeyword(virtualScope, vsp, 7); // keyword: virtual
479 searchForKeyword(staticScope, ssp, 6); // keyword: static
480
481 // search for "operator"
482 if (osp<11 && (osp>=8 || c==operatorScope[osp]) && // character matches substring "operator" followed by 3 arbitrary characters
483 (osp>0 || // inside search string
484 i==0 || // if it is the first character
485 !isId(pc) // the previous may not be a digit
486 )
487 )
488 osp++;
489 else // reset counter
490 osp=0;
491
492 switch(c)
493 {
494 case '"': // quoted string
495 {
496 *dst++=c;
497 i++;
498 for (;i<l;i++) // find end of string
499 {
500 c = src[i];
501 *dst++=c;
502 if (c=='\\' && i+1<l)
503 {
504 i++;
505 c = src[i];
506 *dst++=c;
507 }
508 else if (c=='"')
509 {
510 break;
511 }
512 }
513 }
514 break;
515 case '<': // current char is a <
516 *dst++=c;
517 if (i+1<l &&
518 (isId(nc)) && // next char is an id char
519 (osp<8) // string in front is not "operator"
520 )
521 {
522 *dst++=' '; // add extra space
523 }
524 break;
525 case '>': // current char is a >
526 if (i>0 && !isspace(static_cast<uint8_t>(pc)) &&
527 (isId(pc) || pc=='*' || pc=='&' || pc=='.' || pc=='>') && // prev char is an id char or space or *&.
528 (osp<8 || (osp==8 && pc!='-')) // string in front is not "operator>" or "operator->"
529 )
530 {
531 *dst++=' '; // add extra space in front
532 }
533 *dst++=c;
534 if (i+1<l && (nc=='-' || nc=='&')) // '>-' -> '> -'
535 {
536 *dst++=' '; // add extra space after
537 }
538 break;
539 case ',': // current char is a ,
540 *dst++=c;
541 if (i>0 && !isspace(static_cast<uint8_t>(pc)) &&
542 ((i+1<l && (isId(nc) || nc=='[')) || // the [ is for attributes (see bug702170)
543 (i+2<l && nc=='$' && isId(src[i+2])) || // for PHP: ',$name' -> ', $name'
544 (i+3<l && nc=='&' && src[i+2]=='$' && isId(src[i+3])) // for PHP: ',&$name' -> ', &$name'
545 )
546 )
547 {
548 *dst++=' '; // add extra space after
549 }
550 break;
551 case '^': // CLI 'Type^name' -> 'Type^ name'
552 case '%': // CLI 'Type%name' -> 'Type% name'
553 *dst++=c;
554 if (cliSupport && i+1<l && (isId(nc) || nc=='-'))
555 {
556 *dst++=' '; // add extra space after
557 }
558 break;
559 case ')': // current char is a ) -> ')name' -> ') name'
560 *dst++=c;
561 if (i+1<l && (isId(nc) || nc=='-'))
562 {
563 *dst++=' '; // add extra space after
564 }
565 break;
566 case '*':
567 if (i>0 && pc!=' ' && pc!='\t' && pc!=':' &&
568 pc!='*' && pc!='&' && pc!='(' && pc!='/' && pc!='[' &&
569 pc!='.' && osp<9
570 )
571 // avoid splitting &&, **, .*, operator*, operator->*
572 {
573 *dst++=' ';
574 }
575 *dst++=c;
576 break;
577 case '&':
578 if (i>0 && isId(pc) && osp<9)
579 {
580 if (nc != '=')
581 // avoid splitting operator&=
582 {
583 *dst++=' ';
584 }
585 }
586 *dst++=c;
587 break;
588 case '$': // '$name' -> ' $name'
589 // 'name$name' -> 'name$name'
590 if (isId(pc))
591 {
592 *dst++=c;
593 break;
594 }
595 // else fallthrough
596 case '@': // '@name' -> ' @name'
597 case '\'': // ''name' -> '' name'
598 if (i>0 && i+1<l && pc!='=' && pc!=':' && !isspace(static_cast<uint8_t>(pc)) &&
599 isId(nc) && osp<8) // ")id" -> ") id"
600 {
601 *dst++=' ';
602 }
603 *dst++=c;
604 break;
605 case ':': // current char is a :
606 if (csp==6) // replace const::A by const ::A
607 {
608 *dst++=' ';
609 csp=0;
610 }
611 else if (vosp==9) // replace volatile::A by volatile ::A
612 {
613 *dst++=' ';
614 vosp=0;
615 }
616 else if (vsp==8) // replace virtual::A by virtual ::A
617 {
618 *dst++=' ';
619 vsp=0;
620 }
621 *dst++=c;
622 break;
623 case ' ': // fallthrough
624 case '\n': // fallthrough
625 case '\t':
626 {
627 if (g_charAroundSpace.charMap[static_cast<uint8_t>(pc)].before &&
628 g_charAroundSpace.charMap[static_cast<uint8_t>(nc)].after &&
629 !(pc==',' && nc=='.') &&
630 (osp<8 || (osp>=8 && isId(pc) && isId(nc)))
631 // e.g. 'operator >>' -> 'operator>>',
632 // 'operator "" _x' -> 'operator""_x',
633 // but not 'operator int' -> 'operatorint'
634 )
635 { // keep space
636 *dst++=' ';
637 }
638 else if (ssp==7 && nc=='(') // keep space for 'static ('
639 {
640 *dst++=' ';
641 ssp=0;
642 }
643 else if ((pc=='*' || pc=='&' || pc=='.') && nc=='>')
644 {
645 *dst++=' ';
646 }
647 }
648 break;
649 default:
650 *dst++=c;
651 auto correctKeywordAllowedInsideScope = [&](char cc,size_t &matchLen,size_t totalLen) {
652 if (c==cc && matchLen==totalLen)
653 {
654 if ((i+2<l && src[i+1] == ':' && src[i+2] == ':') || // keyword::
655 ((i>matchLen && src[i-matchLen] == ':' && src[i-matchLen-1] == ':')) // ::keyword
656 ) matchLen = 0;
657 };
658 };
659 correctKeywordAllowedInsideScope('t',csp, 5); // keyword: const
660 correctKeywordAllowedInsideScope('e',vosp,8); // keyword: volatile
661 correctKeywordAllowedInsideScope('l',vsp, 7); // keyword: virtual
662
663 auto correctKeywordNotPartOfScope = [&](char cc,size_t &matchLen,size_t totalLen)
664 {
665 if (c==cc && matchLen==totalLen && i+1<l && // found matching keyword
666 !(isId(nc) || nc==')' || nc==',' || disspace(nc))
667 ) // prevent keyword ::A from being converted to keyword::A
668 {
669 *dst++=' ';
670 matchLen=0;
671 }
672 };
673 correctKeywordNotPartOfScope('t',csp, 5); // keyword: const
674 correctKeywordNotPartOfScope('e',vosp,8); // keyword: volatile
675 correctKeywordNotPartOfScope('l',vsp, 7); // keyword: virtual
676 break;
677 }
678 pc=c;
679 }
680 *dst++='\0';
681 //printf("removeRedundantWhitespace(%s)->%s\n",qPrint(s),growBuf.data());
682 return growBuf.data();
683}
#define THREAD_LOCAL
Definition doxygen.h:29
bool disspace(char c)
Definition dstring.h:62
Token literal values and constants.
Definition CharStream.h:12
CharElem charMap[256]
Definition util.cpp:421
static const char constScope[]
Definition util.cpp:379
static const char staticScope[]
Definition util.cpp:383
static const char virtualScope[]
Definition util.cpp:381
static const char volatileScope[]
Definition util.cpp:380
static CharAroundSpace g_charAroundSpace
Definition util.cpp:424
static const char operatorScope[]
Definition util.cpp:382

References CharAroundSpace::CharElem::after, CharAroundSpace::CharElem::before, CharAroundSpace::charMap, Config_getBool, constScope, DString::data(), disspace(), DString::empty(), g_charAroundSpace, isId(), DString::length(), operatorScope, staticScope, THREAD_LOCAL, virtualScope, and volatileScope.

Referenced by addFrom(), addGlobalFunction(), addMethodToClass(), addVariable(), addVariableToClass(), argListToString(), buildFunctionList(), buildInterfaceAndServiceList(), buildTypedefList(), ClassDefImpl::ClassDefImpl(), extractCanonicalType(), findClassRelation(), DocParser::findDocsForMemberOrCompound(), findMember(), findUsedClassesForClass(), findUsingDeclImports(), ArgumentList::finishTrailingReturnType(), generateFunctionLink(), generateFunctionLink(), generateLink(), getCanonicalTypeForIdentifier(), getLink(), getLink(), getLink(), MemberDefImpl::init(), ClassDefImpl::insertTemplateInstance(), MemberDefImpl::MemberDefImpl(), normalizeNonTemplateArgumentsInString(), parseFuncDecl(), resolveRef(), tempArgListToString(), and writeExceptionListImpl().

◆ replaceAnonymousScopes()

DString replaceAnonymousScopes ( const DString & s,
const DString & replacement = DString() )

Definition at line 155 of file util.cpp.

156{
157 if (s.empty()) return s;
158 static const reg::Ex marker(R"(@\d+)");
159 std::string result = reg::replace(s.str(),marker,
160 !replacement.empty() ? replacement.data() : "__anonymous__");
161 //printf("replaceAnonymousScopes('%s')='%s'\n",qPrint(s),qPrint(result));
162 return result;
163}
std::string replace(std::string_view str, const Ex &re, std::string_view replacement)
Searching in a given input string for parts that match regular expression re and replaces those parts...
Definition regex.cpp:872

References DString::data(), DString::empty(), reg::replace(), and DString::str().

Referenced by addMemberFunction(), findGlobalMember(), and generateDEFForMember().

◆ replaceColorMarkers()

DString replaceColorMarkers ( const DString & str)

Replaces any markers of the form ##AA in input string str by new markers of the form #AABBCC, where #AABBCC represents a valid color, based on the intensity represented by hex number AA and the current HTML_COLORSTYLE_* settings.

Definition at line 4581 of file util.cpp.

4582{
4583 if (str.empty()) return DString();
4584 std::string result;
4585 std::string s=str.str();
4586 static const reg::Ex re(R"(##[0-9A-Fa-f][0-9A-Fa-f])");
4587 reg::Iterator it(s,re);
4589 int hue = Config_getInt(HTML_COLORSTYLE_HUE);
4590 int sat = Config_getInt(HTML_COLORSTYLE_SAT);
4591 int gamma = Config_getInt(HTML_COLORSTYLE_GAMMA);
4592 size_t sl=s.length();
4593 size_t p=0;
4594 for (; it!=end ; ++it)
4595 {
4596 const auto &match = *it;
4597 size_t i = match.position();
4598 size_t l = match.length();
4599 if (i>p) result+=s.substr(p,i-p);
4600 std::string lumStr = match.str().substr(2);
4601#define HEXTONUM(x) (((x)>='0' && (x)<='9') ? ((x)-'0') : \
4602 ((x)>='a' && (x)<='f') ? ((x)-'a'+10) : \
4603 ((x)>='A' && (x)<='F') ? ((x)-'A'+10) : 0)
4604
4605 double r = 0,g = 0,b = 0;
4606 int level = HEXTONUM(lumStr[0])*16+HEXTONUM(lumStr[1]);
4607 ColoredImage::hsl2rgb(hue/360.0,sat/255.0,
4608 pow(level/255.0,gamma/100.0),&r,&g,&b);
4609 int red = static_cast<int>(r*255.0);
4610 int green = static_cast<int>(g*255.0);
4611 int blue = static_cast<int>(b*255.0);
4612 char colStr[8];
4613 colStr[0]='#';
4614 colStr[1]=hex[red>>4];
4615 colStr[2]=hex[red&0xf];
4616 colStr[3]=hex[green>>4];
4617 colStr[4]=hex[green&0xf];
4618 colStr[5]=hex[blue>>4];
4619 colStr[6]=hex[blue&0xf];
4620 colStr[7]=0;
4621 //printf("replacing %s->%s (level=%d)\n",qPrint(lumStr),colStr,level);
4622 result+=colStr;
4623 p=i+l;
4624 }
4625 if (p<sl) result+=s.substr(p);
4626 return result;
4627}
static void hsl2rgb(double h, double s, double l, double *pRed, double *pGreen, double *pBlue)
Definition image.cpp:373
#define HEXTONUM(x)

References Config_getInt, DString::empty(), end(), hex, HEXTONUM, ColoredImage::hsl2rgb(), and DString::str().

Referenced by ResourceMgr::copyResourceAs(), fillColorStyleMaps(), HtmlGenerator::init(), and writeDefaultStyleSheet().

◆ resolveLink()

bool resolveLink ( const DString & scName,
const DString & lr,
bool inSeeBlock,
const Definition ** resContext,
DString & resAnchor,
SrcLangExt lang,
const DString & prefix = DString(),
const FileDef * currentFile = nullptr )

Returns an symbol definition given its name and context for an explicitly linked symbol.

Postcondition
return value true implies *resContext!=0

Definition at line 2316 of file util.cpp.

2325{
2326 *resContext=nullptr;
2327
2328 DString linkRef=lr;
2329 if (lang==SrcLangExt::CSharp)
2330 {
2331 linkRef = mangleCSharpGenericName(linkRef);
2332 }
2333 DString linkRefWithoutTemplates = stripTemplateSpecifiersFromScope(linkRef,false);
2334 AUTO_TRACE("scName='{}',ref='{}'",scName,lr);
2335 const FileDef *fd = nullptr;
2336 const GroupDef *gd = nullptr;
2337 const PageDef *pd = nullptr;
2338 const ClassDef *cd = nullptr;
2339 const DirDef *dir = nullptr;
2340 const ConceptDef *cnd = nullptr;
2341 const ModuleDef *modd = nullptr;
2342 const NamespaceDef *nd = nullptr;
2343 const SectionInfo *si = nullptr;
2344 bool ambig = false;
2345 if (linkRef.empty()) // no reference name!
2346 {
2347 AUTO_TRACE_EXIT("no_ref");
2348 return false;
2349 }
2350 else if ((pd=Doxygen::pageLinkedMap->find(linkRef))) // link to a page
2351 {
2352 gd = pd->getGroupDef();
2353 if (gd)
2354 {
2355 if (!pd->name().empty()) si=SectionManager::instance().find(pd->name());
2356 *resContext=gd;
2357 if (si) resAnchor = si->label();
2358 }
2359 else
2360 {
2361 *resContext=pd;
2362 }
2363 AUTO_TRACE_EXIT("page");
2364 return true;
2365 }
2366 else if ((si=SectionManager::instance().find(prefix+linkRef)))
2367 {
2368 *resContext=si->definition();
2369 resAnchor = si->label();
2370 AUTO_TRACE_EXIT("section anchor={} def={}",resAnchor,si->definition()?si->definition()->name():"<none>");
2371 return true;
2372 }
2373 else if (!prefix.empty() && (si=SectionManager::instance().find(linkRef)))
2374 {
2375 *resContext=si->definition();
2376 resAnchor = si->label();
2377 AUTO_TRACE_EXIT("section anchor={} def={}",resAnchor,si->definition()?si->definition()->name():"<none>");
2378 return true;
2379 }
2380 else if ((pd=Doxygen::exampleLinkedMap->find(linkRef))) // link to an example
2381 {
2382 *resContext=pd;
2383 AUTO_TRACE_EXIT("example");
2384 return true;
2385 }
2386 else if ((gd=Doxygen::groupLinkedMap->find(linkRef))) // link to a group
2387 {
2388 *resContext=gd;
2389 AUTO_TRACE_EXIT("group");
2390 return true;
2391 }
2392 else if ((fd=Doxygen::inputNameLinkedMap->findFileDef(linkRef,ambig)) // file link
2393 && fd->isLinkable())
2394 {
2395 *resContext=fd;
2396 AUTO_TRACE_EXIT("file");
2397 return true;
2398 }
2399 else if ((cd=getClass(linkRef))) // class link
2400 {
2401 *resContext=cd;
2402 resAnchor=cd->anchor();
2403 AUTO_TRACE_EXIT("class");
2404 return true;
2405 }
2406 else if (lang==SrcLangExt::Java &&
2407 (cd=getClass(linkRefWithoutTemplates))) // Java generic class link
2408 {
2409 *resContext=cd;
2410 resAnchor=cd->anchor();
2411 AUTO_TRACE_EXIT("generic");
2412 return true;
2413 }
2414 else if ((cd=getClass(linkRef+"-p"))) // Obj-C protocol link
2415 {
2416 *resContext=cd;
2417 resAnchor=cd->anchor();
2418 AUTO_TRACE_EXIT("protocol");
2419 return true;
2420 }
2421 else if ((cnd=getConcept(linkRef))) // C++20 concept definition
2422 {
2423 *resContext=cnd;
2424 resAnchor=cnd->anchor();
2425 AUTO_TRACE_EXIT("concept");
2426 return true;
2427 }
2428 else if ((modd=ModuleManager::instance().modules().find(linkRef)))
2429 {
2430 *resContext=modd;
2431 resAnchor=modd->anchor();
2432 AUTO_TRACE_EXIT("module");
2433 return true;
2434 }
2435 else if ((nd=Doxygen::namespaceLinkedMap->find(linkRef)))
2436 {
2437 *resContext=nd;
2438 AUTO_TRACE_EXIT("namespace");
2439 return true;
2440 }
2441 else if ((dir=resolveDirLink(linkRef)) && dir->isLinkable())
2442 {
2443 *resContext=dir;
2444 AUTO_TRACE_EXIT("directory");
2445 return true;
2446 }
2447 else // probably a member reference
2448 {
2449 const MemberDef *md = nullptr;
2450 bool res = resolveRef(scName,lr,true,resContext,&md,lang,true,currentFile);
2451 if (md) resAnchor=md->anchor();
2452 AUTO_TRACE_EXIT("member? res={}",res);
2453 return res;
2454 }
2455}
constexpr auto prefix
Definition anchor.cpp:47
virtual bool isLinkable() const =0
virtual DString anchor() const =0
A model of a directory symbol.
Definition dirdef.h:108
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
static PageLinkedMap * exampleLinkedMap
Definition doxygen.h:91
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:92
static GroupLinkedMap * groupLinkedMap
Definition doxygen.h:107
A model of a group of symbols.
Definition groupdef.h:48
const T * find(const std::string &key) const
Definition linkedmap.h:47
static ModuleManager & instance()
A model of a page symbol.
Definition pagedef.h:27
virtual const GroupDef * getGroupDef() const =0
class that provide information about a section.
Definition section.h:58
Definition * definition() const
Definition section.h:77
DString label() const
Definition section.h:69
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
ConceptDef * getConcept(const DString &n)
bool resolveRef(const DString &scName, const DString &name, bool inSeeBlock, const Definition **resContext, const MemberDef **resMember, SrcLangExt lang, bool lookForSpecialization, const FileDef *currentFile, bool checkScope)
Definition util.cpp:2016
DString stripTemplateSpecifiersFromScope(const DString &fullName, bool parentOnly, DString *pLastScopeStripped, DString scopeName, bool allowArtificial)
Definition util.cpp:3695
static const DirDef * resolveDirLink(const DString &linkRef)
Definition util.cpp:2298
DString mangleCSharpGenericName(const DString &name)
Definition util.cpp:5354

References Definition::anchor(), AUTO_TRACE, AUTO_TRACE_EXIT, SectionInfo::definition(), DString::empty(), Doxygen::exampleLinkedMap, LinkedMap< T, Hash, KeyEqual, Map >::find(), getClass(), getConcept(), PageDef::getGroupDef(), Doxygen::groupLinkedMap, Doxygen::inputNameLinkedMap, ModuleManager::instance(), SectionManager::instance(), Definition::isLinkable(), SectionInfo::label(), mangleCSharpGenericName(), Definition::name(), Doxygen::namespaceLinkedMap, Doxygen::pageLinkedMap, prefix, resolveDirLink(), resolveRef(), and stripTemplateSpecifiersFromScope().

Referenced by DocLink::DocLink(), and DocRef::DocRef().

◆ resolveRef()

bool resolveRef ( const DString & scName,
const DString & name,
bool inSeeBlock,
const Definition ** resContext,
const MemberDef ** resMember,
SrcLangExt lang,
bool lookForSpecializations = true,
const FileDef * currentFile = nullptr,
bool checkScope = false )

Returns a symbol definition (compound and/or member) given its name and context.

Postcondition
return value true implies *resContext!=0 or *resMember!=0

Definition at line 2016 of file util.cpp.

2026{
2027 AUTO_TRACE("scope={} name={} inSeeBlock={} lang={} lookForSpecialization={} currentFile={} checkScope={}",
2028 scName,name,inSeeBlock,lang,lookForSpecialization,currentFile ? currentFile->name() : "", checkScope);
2029 //printf("resolveRef(scope=%s,name=%s,inSeeBlock=%d)\n",qPrint(scName),qPrint(name),inSeeBlock);
2030 DString tsName = name;
2031 //bool memberScopeFirst = tsName.find('#')!=-1;
2032 DString fullName = substitute(tsName,"#","::");
2033 if (fullName.find("anonymous_namespace{")==DString::npos)
2034 {
2035 fullName = removeRedundantWhiteSpace(substitute(fullName,".","::",3));
2036 }
2037 else
2038 {
2039 fullName = removeRedundantWhiteSpace(fullName);
2040 }
2041
2042 size_t templStartPos;
2043 if (lang==SrcLangExt::CSharp && (templStartPos=fullName.find('<'))!=DString::npos)
2044 {
2045 size_t templEndPos = fullName.rfind('>');
2046 if (templEndPos!=DString::npos)
2047 {
2048 fullName = mangleCSharpGenericName(fullName.left(templEndPos+1))+fullName.mid(templEndPos+1);
2049 AUTO_TRACE_ADD("C# mangled name='{}'",fullName);
2050 }
2051 }
2052
2053 size_t bracePos = findParameterList(fullName);
2054 size_t endNamePos = bracePos!=DString::npos ? bracePos : fullName.length();
2055 size_t scopePos = fullName.rfind("::",endNamePos);
2056 bool explicitScope = fullName.startsWith("::") && // ::scope or #scope
2057 ((scopePos!=DString::npos && scopePos>2) || // ::N::A
2058 tsName.startsWith("::") || // ::foo in local scope
2059 scName==nullptr // #foo in global scope
2060 );
2061 bool allowTypeOnly=false;
2062
2063 // default result values
2064 *resContext=nullptr;
2065 *resMember=nullptr;
2066
2067 if (bracePos==DString::npos) // simple name
2068 {
2069 // the following if() was commented out for releases in the range
2070 // 1.5.2 to 1.6.1, but has been restored as a result of bug report 594787.
2071 if (!inSeeBlock && scopePos==DString::npos && isLowerCase(tsName))
2072 { // link to lower case only name => do not try to autolink
2073 AUTO_TRACE_ADD("false");
2074 return false;
2075 }
2076
2077 ClassDef *cd=nullptr;
2078 NamespaceDef *nd=nullptr;
2079 ConceptDef *cnd=nullptr;
2080 ModuleDef *modd=nullptr;
2081
2082 //printf("scName=%s fullName=%s\n",qPrint(scName),qPrint(fullName));
2083
2084 // check if this is a class or namespace reference
2085 if (scName!=fullName && getScopeDefs(scName,fullName,cd,cnd,nd,modd))
2086 {
2087 //printf("found scopeDef\n");
2088 if (cd) // scope matches that of a class
2089 {
2090 *resContext = cd;
2091 }
2092 else if (cnd)
2093 {
2094 *resContext = cnd;
2095 }
2096 else if (modd)
2097 {
2098 *resContext = modd;
2099 }
2100 else // scope matches that of a namespace
2101 {
2102 ASSERT(nd!=nullptr);
2103 *resContext = nd;
2104 }
2105 AUTO_TRACE_ADD("true");
2106 return true;
2107 }
2108 else if (scName==fullName || (!inSeeBlock && scopePos==DString::npos))
2109 // nothing to link => output plain text
2110 {
2111 //printf("found scName=%s fullName=%s scName==fullName=%d "
2112 // "inSeeBlock=%d scopePos=%d!\n",
2113 // qPrint(scName),qPrint(fullName),scName==fullName,inSeeBlock,scopePos);
2114
2115 // at this point we have a bare word that is not a class or namespace
2116 // we should also allow typedefs or enums to be linked, but not for instance member
2117 // functions, otherwise 'Foo' would always link to the 'Foo()' constructor instead of the
2118 // 'Foo' class. So we use this flag as a filter.
2119 allowTypeOnly=true;
2120 }
2121
2122 // continue search...
2123 }
2124
2125 // extract userscope+name
2126 DString nameStr=fullName.left(endNamePos);
2127 if (explicitScope) nameStr=nameStr.mid(2);
2128
2129
2130 // extract arguments
2131 DString argsStr;
2132 if (bracePos!=DString::npos) argsStr=fullName.mid(bracePos);
2133
2134 // strip template specifier
2135 // TODO: match against the correct partial template instantiation
2136 size_t templPos = nameStr.find('<');
2137 bool tryUnspecializedVersion = false;
2138 if (templPos!=DString::npos && nameStr.find("operator")==DString::npos)
2139 {
2140 size_t endTemplPos=nameStr.rfind('>');
2141 if (endTemplPos!=DString::npos)
2142 {
2143 if (!lookForSpecialization)
2144 {
2145 nameStr=nameStr.left(templPos)+nameStr.mid(endTemplPos+1);
2146 }
2147 else
2148 {
2149 tryUnspecializedVersion = true;
2150 }
2151 }
2152 }
2153
2154 DString scopeStr=scName;
2155 if (!explicitScope && nameStr.length()>scopeStr.length() && leftScopeMatch(scopeStr,nameStr))
2156 {
2157 nameStr=nameStr.mid(scopeStr.length()+2);
2158 }
2159
2160 const GroupDef *gd = nullptr;
2161 const ConceptDef *cnd = nullptr;
2162 const ModuleDef *modd = nullptr;
2163
2164 // check if nameStr is a member or global.
2165 //printf("getDefs(scope=%s,name=%s,args=%s checkScope=%d)\n",
2166 // qPrint(scopeStr), qPrint(nameStr), qPrint(argsStr),checkScope);
2167 GetDefInput input(scopeStr,nameStr,argsStr);
2168 input.forceEmptyScope = explicitScope;
2169 input.currentFile = currentFile;
2170 input.checkCV = true;
2171 GetDefResult result = getDefs(input);
2172 if (result.found)
2173 {
2174 //printf("after getDefs checkScope=%d nameStr=%s\n",checkScope,qPrint(nameStr));
2175 size_t np = nameStr.find("::");
2176 if (checkScope && result.md && result.md->getOuterScope()==Doxygen::globalScope &&
2177 !result.md->isStrongEnumValue() &&
2178 (!scopeStr.empty() || (np!=DString::npos && np>0)))
2179 {
2180 // we did find a member, but it is a global one while we were explicitly
2181 // looking for a scoped variable. See bug 616387 for an example why this check is needed.
2182 // note we do need to support autolinking to "::symbol" hence the >0
2183 //printf("not global member!\n");
2184 *resContext=nullptr;
2185 *resMember=nullptr;
2186 AUTO_TRACE_ADD("false");
2187 return false;
2188 }
2189 //printf("after getDefs md=%p cd=%p fd=%p nd=%p gd=%p\n",md,cd,fd,nd,gd);
2190 if (result.md)
2191 {
2192 if (!allowTypeOnly || result.md->isTypedef() || result.md->isEnumerate())
2193 {
2194 *resMember=result.md;
2195 *resContext=result.md;
2196 }
2197 else // md is not a type, but we explicitly expect one
2198 {
2199 *resContext=nullptr;
2200 *resMember=nullptr;
2201 AUTO_TRACE_ADD("false");
2202 return false;
2203 }
2204 }
2205 else if (result.cd) *resContext=result.cd;
2206 else if (result.nd) *resContext=result.nd;
2207 else if (result.fd) *resContext=result.fd;
2208 else if (result.gd) *resContext=result.gd;
2209 else if (result.cnd) *resContext=result.cnd;
2210 else if (result.modd) *resContext=result.modd;
2211 else
2212 {
2213 *resContext=nullptr; *resMember=nullptr;
2214 AUTO_TRACE_ADD("false");
2215 return false;
2216 }
2217 //printf("member=%s (md=%p) anchor=%s linkable()=%d context=%s\n",
2218 // qPrint(md->name()), md, qPrint(md->anchor()), md->isLinkable(), qPrint((*resContext)->name()));
2219 AUTO_TRACE_ADD("true");
2220 return true;
2221 }
2222 else if (inSeeBlock && !nameStr.empty() && (gd=Doxygen::groupLinkedMap->find(nameStr)))
2223 { // group link
2224 *resContext=gd;
2225 AUTO_TRACE_ADD("true");
2226 return true;
2227 }
2228 else if ((cnd=Doxygen::conceptLinkedMap->find(nameStr)))
2229 {
2230 *resContext=cnd;
2231 AUTO_TRACE_ADD("true");
2232 return true;
2233 }
2234 else if ((modd=ModuleManager::instance().modules().find(nameStr)))
2235 {
2236 *resContext=modd;
2237 AUTO_TRACE_ADD("true");
2238 return true;
2239 }
2240 else if (tsName.find('.')!=DString::npos) // maybe a link to a file
2241 {
2242 bool ambig = false;
2243 const FileDef *fd=Doxygen::inputNameLinkedMap->findFileDef(tsName,ambig);
2244 if (fd && !ambig)
2245 {
2246 *resContext=fd;
2247 AUTO_TRACE_ADD("true");
2248 return true;
2249 }
2250 }
2251
2252 if (tryUnspecializedVersion)
2253 {
2254 bool b = resolveRef(scName,name,inSeeBlock,resContext,resMember,lang,false,nullptr,checkScope);
2255 AUTO_TRACE_ADD("{}",b);
2256 return b;
2257 }
2258 if (bracePos!=DString::npos) // Try without parameters as well, could be a constructor invocation
2259 {
2260 *resContext=getClass(fullName.left(bracePos));
2261 if (*resContext)
2262 {
2263 AUTO_TRACE_ADD("true");
2264 return true;
2265 }
2266 }
2267 //printf("resolveRef: %s not found!\n",qPrint(name));
2268
2269 AUTO_TRACE_ADD("false");
2270 return false;
2271}
virtual Definition * getOuterScope() const =0
static ConceptLinkedMap * conceptLinkedMap
Definition doxygen.h:90
virtual bool isStrongEnumValue() const =0
virtual bool isEnumerate() const =0
static size_t findParameterList(const DString &name)
Returns the position in the string where a function parameter list begins, or DString::npos if one is...
Definition util.cpp:689
GetDefResult getDefs(const GetDefInput &input)
Definition util.cpp:1874
static bool getScopeDefs(const DString &docScope, const DString &scope, ClassDef *&cd, ConceptDef *&cnd, NamespaceDef *&nd, ModuleDef *&modd)
Definition util.cpp:1944
static bool isLowerCase(DString &s)
Definition util.cpp:2007

References ASSERT, AUTO_TRACE, AUTO_TRACE_ADD, GetDefResult::cd, GetDefInput::checkCV, GetDefResult::cnd, Doxygen::conceptLinkedMap, GetDefInput::currentFile, DString::empty(), GetDefResult::fd, DString::find(), LinkedMap< T, Hash, KeyEqual, Map >::find(), FileNameLinkedMap::findFileDef(), findParameterList(), GetDefInput::forceEmptyScope, GetDefResult::found, GetDefResult::gd, getClass(), getDefs(), Definition::getOuterScope(), getScopeDefs(), Doxygen::globalScope, Doxygen::groupLinkedMap, Doxygen::inputNameLinkedMap, ModuleManager::instance(), MemberDef::isEnumerate(), isLowerCase(), MemberDef::isStrongEnumValue(), MemberDef::isTypedef(), DString::left(), leftScopeMatch(), DString::length(), mangleCSharpGenericName(), GetDefResult::md, DString::mid(), GetDefResult::modd, Definition::name(), GetDefResult::nd, DString::npos, removeRedundantWhiteSpace(), resolveRef(), DString::rfind(), DString::startsWith(), and substitute().

Referenced by DocParser::handleLinkedWord(), resolveLink(), and resolveRef().

◆ resolveTypeDef()

DString resolveTypeDef ( const Definition * d,
const DString & name,
const Definition ** typedefContext = nullptr )

Definition at line 232 of file util.cpp.

234{
235 AUTO_TRACE("context='{}' qualifiedName='{}'",context?context->name():"",qualifiedName);
236 DString result;
237 if (qualifiedName.empty())
238 {
239 AUTO_TRACE_EXIT("empty name");
240 return result;
241 }
242
243 const Definition *mContext=context;
244 if (typedefContext) *typedefContext=context;
245
246 // see if the qualified name has a scope part
247 if (qualifiedName.find('<')!=DString::npos)
248 {
249 AUTO_TRACE_EXIT("template");
250 return result;
251 }
252 size_t scopeIndex = qualifiedName.rfind("::");
253 DString resName=qualifiedName;
254 if (scopeIndex!=DString::npos) // strip scope part for the name
255 {
256 resName=qualifiedName.mid(scopeIndex+2);
257 if (resName.empty())
258 {
259 AUTO_TRACE_EXIT("invalid format");
260 return result;
261 }
262 }
263 const MemberDef *md=nullptr;
264 while (mContext && md==nullptr)
265 {
266 // step 1: get the right scope
267 const Definition *resScope=mContext;
268 if (scopeIndex!=DString::npos)
269 {
270 // split-off scope part
271 DString resScopeName = qualifiedName.left(scopeIndex);
272 //printf("resScopeName='%s'\n",qPrint(resScopeName));
273
274 // look-up scope in context
275 int is=0,ps=0,l=0;
276 while ((is=getScopeFragment(resScopeName,ps,&l))!=-1)
277 {
278 DString qualScopePart = resScopeName.mid(is,l);
279 DString tmp = resolveTypeDef(mContext,qualScopePart);
280 if (!tmp.empty()) qualScopePart=tmp;
281 resScope = resScope->findInnerCompound(qualScopePart);
282 //printf("qualScopePart='%s' resScope=%p\n",qPrint(qualScopePart),resScope);
283 if (resScope==nullptr) break;
284 ps=is+l;
285 }
286 }
287 AUTO_TRACE_ADD("resScope='{}' resName='{}'",resScope?resScope->name():"",resName);
288
289 // step 2: get the member
290 if (resScope) // no scope or scope found in the current context
291 {
292 //printf("scope found: %s, look for typedef %s\n",
293 // qPrint(resScope->qualifiedName()),qPrint(resName));
294 MemberNameLinkedMap *mnd=nullptr;
295 bool searchRelated=false;
296 bool mustBeRelated=false;
297 if (resScope->definitionType()==Definition::TypeClass)
298 {
300 }
301 else
302 {
304 searchRelated=true;
305 }
306 MemberName *mn=mnd->find(resName);
307 if (mn==0 && searchRelated)
308 {
310 mustBeRelated=true;
311 }
312 if (mn)
313 {
314 int minDist=-1;
315 for (const auto &tmd_p : *mn)
316 {
317 const MemberDef *tmd = tmd_p.get();
318 AUTO_TRACE_ADD("found candidate member '{}' isTypeDef={}' isRelated={} mustBeRelated={}",
319 tmd->name(),tmd->isTypedef(),tmd->isRelated(),mustBeRelated);
320 //printf("Found member %s resScope=%s outerScope=%s mContext=%p\n",
321 // qPrint(tmd->name()),qPrint( resScope->name()),
322 // qPrint(tmd->getOuterScope()->name()), mContext);
323 if (tmd->isTypedef())
324 {
325 if (resScope==Doxygen::globalScope && tmd->isRelated() && mustBeRelated)
326 {
327 md = tmd;
328 }
329 else
330 {
331 SymbolResolver resolver;
332 int dist=resolver.isAccessibleFrom(resScope,tmd);
333 if (dist!=-1 && (md==nullptr || dist<minDist))
334 {
335 md = tmd;
336 minDist = dist;
337 }
338 }
339 }
340 }
341 }
342 }
343 mContext=mContext->getOuterScope();
344 }
345
346 AUTO_TRACE_ADD("md='{}'",md?md->name():"");
347 // step 3: get the member's type
348 if (md)
349 {
350 //printf(">>resolveTypeDef: Found typedef name '%s' in scope '%s' value='%s' args='%s'\n",
351 // qPrint(qualifiedName),qPrint(context->name()),qPrint(md->typeString()),qPrint(md->argsString())
352 // );
353 result=md->typeString();
354 DString args = md->argsString();
355 if (args.find(")(")!=DString::npos) // typedef of a function/member pointer
356 {
357 result+=args;
358 }
359 else if (args.find('[')!=DString::npos) // typedef of an array
360 {
361 result+=args;
362 }
363 if (typedefContext) *typedefContext=md->getOuterScope();
364 }
365 else
366 {
367 //printf(">>resolveTypeDef: Typedef '%s' not found in scope '%s'!\n",
368 // qPrint(qualifiedName),context ? qPrint(context->name()) : "<global>");
369 }
370 AUTO_TRACE_EXIT("result='{}'",result);
371 return result;
372}
virtual const Definition * findInnerCompound(const DString &name) const =0
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
virtual DString argsString() const =0
virtual bool isRelated() const =0
virtual DString typeString() const =0
Ordered dictionary of MemberName objects.
Definition membername.h:61
int isAccessibleFrom(const Definition *scope, const Definition *item)
Checks if symbol item is accessible from within scope.
DString resolveTypeDef(const Definition *context, const DString &qualifiedName, const Definition **typedefContext)
Definition util.cpp:232
int getScopeFragment(const DString &s, int p, int *l)
Definition util.cpp:3807

References MemberDef::argsString(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, Definition::definitionType(), DString::empty(), DString::find(), LinkedMap< T, Hash, KeyEqual, Map >::find(), Definition::findInnerCompound(), Doxygen::functionNameLinkedMap, Definition::getOuterScope(), getScopeFragment(), Doxygen::globalScope, SymbolResolver::isAccessibleFrom(), MemberDef::isRelated(), MemberDef::isTypedef(), DString::left(), Doxygen::memberNameLinkedMap, DString::mid(), Definition::name(), DString::npos, resolveTypeDef(), DString::rfind(), Definition::TypeClass, and MemberDef::typeString().

Referenced by findUsedClassesForClass(), getCanonicalTemplateSpec(), getCanonicalTypeForIdentifier(), isVarWithConstructor(), and resolveTypeDef().

◆ rightScopeMatch()

bool rightScopeMatch ( const DString & scope,
const DString & name )

Definition at line 734 of file util.cpp.

735{
736 size_t sl=scope.length();
737 size_t nl=name.length();
738 return (name==scope || // equal
739 (scope.right(nl)==name && // substring
740 sl>1+nl && scope.at(sl-nl-1)==':' && scope.at(sl-nl-2)==':' // scope
741 )
742 );
743}

References DString::at(), DString::length(), and DString::right().

Referenced by addMemberFunction(), findScopeFromQualifiedName(), and isRecursiveBaseClass().

◆ selectBlocks()

DString selectBlocks ( const DString & s,
const SelectionBlockList & blockList,
const SelectionMarkerInfo & markerInfo )

remove disabled blocks and all block markers from s and return the result as a string

Definition at line 5029 of file util.cpp.

5030{
5031 if (s.empty()) return s;
5032
5033 // helper to find the end of a block
5034 auto skipBlock = [&markerInfo](const char *p,const SelectionBlock &blk)
5035 {
5036 char c = 0;
5037 while ((c=*p))
5038 {
5039 if (c==markerInfo.markerChar && dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // end marker
5040 {
5041 size_t len = markerInfo.endLen;
5042 bool negate = *(p+markerInfo.endLen)=='!';
5043 if (negate) len++;
5044 size_t blkNameLen = dstrlen(blk.name);
5045 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5046 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5047 {
5048 //printf("Found end marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5049 return p+len+blkNameLen+markerInfo.closeLen;
5050 }
5051 else // not the right marker id
5052 {
5053 p++;
5054 }
5055 }
5056 else // not and end marker
5057 {
5058 p++;
5059 }
5060 }
5061 return p;
5062 };
5063
5064 DString result;
5065 result.reserve(s.length());
5066 const char *p = s.data();
5067 char c = 0;
5068 while ((c=*p))
5069 {
5070 if (c==markerInfo.markerChar) // potential start of marker
5071 {
5072 if (dstrncmp(p,markerInfo.beginStr,markerInfo.beginLen)==0) // start of begin marker
5073 {
5074 bool found = false;
5075 size_t len = markerInfo.beginLen;
5076 bool negate = *(p+len)=='!';
5077 if (negate) len++;
5078 for (const auto &blk : blockList)
5079 {
5080 size_t blkNameLen = dstrlen(blk.name);
5081 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5082 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5083 {
5084 bool blockEnabled = blk.enabled!=negate;
5085 //printf("Found start marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5086 p+=len+blkNameLen+markerInfo.closeLen;
5087 if (!blockEnabled) // skip until the end of the block
5088 {
5089 //printf("skipping block\n");
5090 p=skipBlock(p,blk);
5091 }
5092 found=true;
5093 break;
5094 }
5095 }
5096 if (!found) // unknown marker id
5097 {
5098 result+=c;
5099 p++;
5100 }
5101 }
5102 else if (dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // start of end marker
5103 {
5104 bool found = false;
5105 size_t len = markerInfo.endLen;
5106 bool negate = *(p+len)=='!';
5107 if (negate) len++;
5108 for (const auto &blk : blockList)
5109 {
5110 size_t blkNameLen = dstrlen(blk.name);
5111 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5112 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5113 {
5114 //printf("Found end marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5115 p+=len+blkNameLen+markerInfo.closeLen;
5116 found=true;
5117 break;
5118 }
5119 }
5120 if (!found) // unknown marker id
5121 {
5122 result+=c;
5123 p++;
5124 }
5125 }
5126 else // not a start or end marker
5127 {
5128 result+=c;
5129 p++;
5130 }
5131 }
5132 else // not a marker character
5133 {
5134 result+=c;
5135 p++;
5136 }
5137 }
5138 //printf("====\n%s\n-----\n%s\n~~~~\n",qPrint(s),qPrint(result));
5139 return result;
5140}
uint32_t dstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
Definition dstring.h:39

References SelectionMarkerInfo::beginLen, SelectionMarkerInfo::beginStr, SelectionMarkerInfo::closeLen, SelectionMarkerInfo::closeStr, DString::data(), dstrlen(), dstrncmp(), DString::empty(), SelectionMarkerInfo::endLen, SelectionMarkerInfo::endStr, DString::length(), SelectionMarkerInfo::markerChar, and DString::reserve().

Referenced by substituteHtmlKeywords(), and substituteLatexKeywords().

◆ showDate()

DString showDate ( const DString & fmt)

Definition at line 2576 of file util.cpp.

2577{
2578 // get the current date and time
2579 std::tm dat{};
2580 int specFormat=0;
2581 DString specDate = "";
2582 DString err = dateTimeFromString(specDate,dat,specFormat);
2583
2584 // do the conversion
2585 int usedFormat=0;
2586 return formatDateTime(fmt,dat,usedFormat);
2587}
DString formatDateTime(const DString &format, const std::tm &dt, int &formatUsed)
Return a string representation for a given std::tm value that is formatted according to the pattern g...
Definition datetime.cpp:176
DString dateTimeFromString(const DString &spec, std::tm &dt, int &format)
Returns the filled in std::tm for a given string representing a date and/or time.
Definition datetime.cpp:135
Definition message.h:146

References dateTimeFromString(), err, and formatDateTime().

Referenced by substituteHtmlKeywords(), and substituteLatexKeywords().

◆ stackTrace()

void stackTrace ( )

Definition at line 4319 of file util.cpp.

4320{
4321#ifdef TRACINGSUPPORT
4322 void *backtraceFrames[128];
4323 int frameCount = backtrace(backtraceFrames, 128);
4324 const size_t cmdLen = 40960;
4325 static char cmd[cmdLen];
4326 char *p = cmd;
4327 p += snprintf(p,cmdLen,"/usr/bin/atos -p %d ", (int)getpid());
4328 for (int x = 0; x < frameCount; x++)
4329 {
4330 p += snprintf(p,cmdLen,"%p ", backtraceFrames[x]);
4331 }
4332 fprintf(stderr,"========== STACKTRACE START ==============\n");
4333 if (FILE *fp = Portable::popen(cmd, "r"))
4334 {
4335 char resBuf[512];
4336 while (size_t len = fread(resBuf, 1, sizeof(resBuf), fp))
4337 {
4338 fwrite(resBuf, 1, len, stderr);
4339 }
4340 Portable::pclose(fp);
4341 }
4342 fprintf(stderr,"============ STACKTRACE END ==============\n");
4343 //fprintf(stderr,"%s\n", frameStrings[x]);
4344#endif
4345}

References Portable::pclose(), and Portable::popen().

◆ stripAnonymousNamespaceScope()

DString stripAnonymousNamespaceScope ( const DString & s)

Definition at line 167 of file util.cpp.

168{
169 int i=0,p=0,l=0;
170 DString newScope;
171 int sl = static_cast<int>(s.length());
172 while ((i=getScopeFragment(s,p,&l))!=-1)
173 {
174 //printf("Scope fragment %s\n",qPrint(s.mid(i,l)));
175 if (Doxygen::namespaceLinkedMap->find(s.left(i+l))!=nullptr)
176 {
177 if (s.at(i)!='@')
178 {
179 if (!newScope.empty()) newScope+="::";
180 newScope+=s.mid(i,l);
181 }
182 }
183 else if (i<sl)
184 {
185 if (!newScope.empty()) newScope+="::";
186 newScope+=s.right(sl-i);
187 goto done;
188 }
189 p=i+l;
190 }
191done:
192 //printf("stripAnonymousNamespaceScope('%s')='%s'\n",qPrint(s),qPrint(newScope));
193 return newScope;
194}

References DString::at(), DString::empty(), getScopeFragment(), DString::left(), DString::length(), DString::mid(), Doxygen::namespaceLinkedMap, and DString::right().

Referenced by addMemberFunction(), addPageToContext(), addVariable(), buildNamespaceList(), computeTemplateClassRelations(), extractClassName(), findGroupScope(), findUsingDeclImports(), findUsingDirectives(), and resolveClassNestingRelations().

◆ stripExtension()

◆ stripExtensionGeneral()

DString stripExtensionGeneral ( const DString & fName,
const DString & ext )

◆ stripFromIncludePath()

DString stripFromIncludePath ( const DString & path)

strip part of path if it matches one of the paths in the Config_getList(INCLUDE_PATH) list

Definition at line 227 of file util.cpp.

228{
229 return stripFromPath(path,Config_getList(STRIP_FROM_INC_PATH));
230}
static DString stripFromPath(const DString &p, StringVector l)
Definition util.cpp:196

References Config_getList, and stripFromPath().

Referenced by MemberDefImpl::_writeGroupInclude(), addIncludeFile(), FileNameLinkedMap::findFileDef(), and FileNameLinkedMap::showFileDefMatches().

◆ stripFromPath()

◆ stripIndentation()

DString stripIndentation ( const DString & s,
bool skipFirstLine = false )

Definition at line 4696 of file util.cpp.

4697{
4698 if (s.empty()) return s; // empty string -> we're done
4699
4700 //printf("stripIndentation:\n%s\n------\n",qPrint(s));
4701 // compute minimum indentation over all lines
4702 const char *p=s.data();
4703 char c=0;
4704 int indent=0;
4705 int minIndent=1000000; // "infinite"
4706 bool searchIndent=true;
4707 int tabSize=Config_getInt(TAB_SIZE);
4708 bool skipFirst = skipFirstLine;
4709 while ((c=*p++))
4710 {
4711 if (c=='\t') { indent+=tabSize - (indent%tabSize); }
4712 else if (c=='\n') { indent=0; searchIndent=true; skipFirst=false; }
4713 else if (c==' ') { indent++; }
4714 else if (searchIndent && !skipFirst)
4715 {
4716 searchIndent=false;
4717 if (indent<minIndent) minIndent=indent;
4718 }
4719 }
4720
4721 // no indent to remove -> we're done
4722 if (minIndent==0) return substitute(s,"@ilinebr","\\ilinebr");
4723
4724 // remove minimum indentation for each line
4725 TextStream result;
4726 p=s.data();
4727 indent=0;
4728 skipFirst=skipFirstLine;
4729 while ((c=*p++))
4730 {
4731 if (c=='\n') // start of new line
4732 {
4733 indent=0;
4734 result << c;
4735 skipFirst=false;
4736 }
4737 else if (indent<minIndent && !skipFirst) // skip until we reach minIndent
4738 {
4739 if (c=='\t')
4740 {
4741 int newIndent = indent+tabSize-(indent%tabSize);
4742 int i=newIndent;
4743 while (i>minIndent) // if a tab crosses the minIndent boundary fill the rest with spaces
4744 {
4745 result << ' ';
4746 i--;
4747 }
4748 indent=newIndent;
4749 }
4750 else // space
4751 {
4752 indent++;
4753 }
4754 }
4755 else if (c=='\\' && literal_at(p,"ilinebr "))
4756 // we also need to remove the indentation after a \ilinebr command at the end of a line
4757 {
4758 result << "\\ilinebr ";
4759 p+=8;
4760 int skipAmount=0;
4761 for (int j=0;j<minIndent;j++) if (*(p+j)==' ') skipAmount++; // test to see if we have the indent
4762 if (skipAmount==minIndent)
4763 {
4764 p+=skipAmount; // remove the indent
4765 }
4766 }
4767 else if (c=='@' && literal_at(p,"ilinebr"))
4768 {
4769 result << "\\ilinebr";
4770 p+=7;
4771 }
4772 else // copy anything until the end of the line
4773 {
4774 result << c;
4775 }
4776 }
4777
4778 //printf("stripIndentation: result=\n%s\n------\n",qPrint(result.str()));
4779
4780 return result.str();
4781}
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

References Config_getInt, DString::data(), DString::empty(), literal_at(), TextStream::str(), and substitute().

Referenced by handleCommentBlock(), handleCommentBlock(), handleCommentBlock(), handleParametersCommentBlocks(), DocPara::handleStartCode(), and MarkdownOutlineParser::parseInput().

◆ stripIndentationVerbatim()

void stripIndentationVerbatim ( DString & doc,
size_t indentationLevel,
bool skipFirstLine = true )

Definition at line 4785 of file util.cpp.

4786{
4787 //printf("stripIndentationVerbatim(level=%d):\n%s\n------\n",indentationLevel,qPrint(doc));
4788 if (indentationLevel <= 0 || doc.empty()) return; // nothing to strip
4789
4790 // by stripping content the string will only become shorter so we write the results
4791 // back into the input string and then resize it at the end.
4792 char c = 0;
4793 const char *src = doc.data();
4794 char *dst = doc.rawData();
4795 bool insideIndent = !skipFirstLine; // skip the initial line from stripping
4796 size_t cnt = 0;
4797 if (!skipFirstLine) cnt = indentationLevel;
4798 while ((c=*src++))
4799 {
4800 // invariant: dst<=src
4801 switch(c)
4802 {
4803 case '\n':
4804 *dst++ = c;
4805 insideIndent = true;
4806 cnt = indentationLevel;
4807 break;
4808 case ' ':
4809 if (insideIndent)
4810 {
4811 if (cnt>0) // count down the spacing until the end of the indent
4812 {
4813 cnt--;
4814 }
4815 else // reached the end of the indent, start of the part of the line to keep
4816 {
4817 insideIndent = false;
4818 *dst++ = c;
4819 }
4820 }
4821 else // part after indent, copy to the output
4822 {
4823 *dst++ = c;
4824 }
4825 break;
4826 default:
4827 insideIndent = false;
4828 *dst++ = c;
4829 break;
4830 }
4831 }
4832 doc.resize(static_cast<uint32_t>(dst-doc.data()));
4833 //printf("stripIndentationVerbatim: result=\n%s\n------\n",qPrint(doc));
4834}
void resize(size_t newlen)
Definition dstring.h:209
char * rawData()
Returns a writable pointer to the data.
Definition dstring.h:166

References DString::data(), DString::empty(), DString::rawData(), and DString::resize().

Referenced by MemberDefImpl::setInitializer().

◆ stripLeadingAndTrailingEmptyLines()

DString stripLeadingAndTrailingEmptyLines ( const DString & s,
int & docLine )

Special version of DString::stripWhiteSpace() that only strips completely blank lines.

Parameters
sthe string to be stripped
docLinethe line number corresponding to the start of the string. This will be adjusted based on the number of lines stripped from the start.
Returns
The stripped string.

Definition at line 3996 of file util.cpp.

3997{
3998 if (s.empty()) return DString();
3999 const char *p = s.data();
4000
4001 // search for leading empty lines
4002 int i=0,li=-1,l=static_cast<int>(s.length());
4003 char c = 0;
4004 while ((c=*p))
4005 {
4006 if (c==' ' || c=='\t' || c=='\r') { i++; p++; }
4007 else if (c=='\\' && literal_at(p,"\\ilinebr")) { i+=8; li=i; p+=8; }
4008 else if (c=='\n') { i++; li=i; docLine++; p++; }
4009 else break;
4010 }
4011
4012 // search for trailing empty lines
4013 int b=l-1,bi=-1;
4014 p=s.data()+b;
4015 while (b>=0)
4016 {
4017 c=*p;
4018 if (c==' ' || c=='\t' || c=='\r') { b--; p--; }
4019 else if (c=='r' && b>=7 && literal_at(p-7,"\\ilinebr")) { bi=b-7; b-=8; p-=8; }
4020 else if (c=='>' && b>=11 && literal_at(p-11,"\\ilinebr<br>")) { bi=b-11; b-=12; p-=12; }
4021 else if (c=='\n') { bi=b; b--; p--; }
4022 else break;
4023 }
4024
4025 // return whole string if no leading or trailing lines where found
4026 if (li==-1 && bi==-1) return s;
4027
4028 // return substring
4029 if (bi==-1) bi=l;
4030 if (li==-1) li=0;
4031 if (bi<=li) return DString(); // only empty lines
4032 //printf("docLine='%s' len=%d li=%d bi=%d\n",qPrint(s),s.length(),li,bi);
4033 return s.mid(li,bi-li);
4034}

References DString::data(), DString::empty(), DString::length(), literal_at(), and DString::mid().

Referenced by DefinitionImpl::_setBriefDescription(), DocGroup::addDocs(), VHDLOutlineParser::checkInlineCode(), DocPara::handleCommand(), CommentScanner::parseCommentBlock(), and toDefinition().

◆ stripPath()

DString stripPath ( const DString & s)

Definition at line 3969 of file util.cpp.

3970{
3971 DString result=s;
3972 if (size_t i=result.rfind('/'); i!=DString::npos)
3973 {
3974 result=result.mid(i+1);
3975 }
3976 if (size_t i=result.rfind('\\'); i!=DString::npos)
3977 {
3978 result=result.mid(i+1);
3979 }
3980 return result;
3981}

References DString::mid(), DString::npos, and DString::rfind().

Referenced by LatexGenerator::addLabel(), anonymous_namespace{tagreader.cpp}::TagFileParser::buildLists(), RTFGenerator::endDoxyAnchor(), LatexGenerator::endIndexItem(), LatexGenerator::endIndexValue(), LatexGenerator::endTitleHead(), makeBaseName(), objectLinkToString(), objectLinkToString(), objectLinkToString(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), XmlDocVisitor::operator()(), DotFilePatcher::run(), SearchIndexExternal::setCurrentDoc(), DocbookGenerator::startDoxyAnchor(), LatexGenerator::startDoxyAnchor(), DocbookGenerator::startFile(), LatexGenerator::startFile(), RTFGenerator::startFile(), DocbookDocVisitor::startLink(), LatexDocVisitor::startLink(), RTFDocVisitor::startLink(), DocbookDocVisitor::startMermaidFile(), LatexDocVisitor::startMermaidFile(), LatexDocVisitor::startPlantUmlFile(), DocbookGenerator::startSection(), LatexGenerator::startSection(), LatexGenerator::startTextLink(), RTFGenerator::startTextLink(), substituteHtmlKeywords(), substituteLatexKeywords(), LatexGenerator::writeAnchor(), RTFGenerator::writeAnchor(), LatexCodeGenerator::writeCodeLink(), RTFCodeGenerator::writeCodeLink(), DocbookCodeGenerator::writeCodeLinkLine(), MemberList::writeDeclarations(), DocbookDocVisitor::writeDiaFile(), writeDocbookLink(), LatexCodeGenerator::writeLineNumber(), RTFCodeGenerator::writeLineNumber(), DocbookDocVisitor::writeMermaidFile(), LatexDocVisitor::writeMermaidFile(), DocbookDocVisitor::writePlantUMLFile(), LatexDocVisitor::writePlantUMLFile(), RTFGenerator::writeRTFReference(), and RTFGenerator::writeStartAnnoItem().

◆ stripScope()

DString stripScope ( const DString & name)

Strips the scope from a name. Examples: A::B will return A and A<T>::B<N::C<D> > will return A<T>.

Definition at line 3118 of file util.cpp.

3119{
3120 DString result = name;
3121 int l = static_cast<int>(result.length());
3122 int p = 0;
3123 bool done = false;
3124 bool skipBracket=false; // if brackets do not match properly, ignore them altogether
3125 int count=0;
3126 int round=0;
3127
3128 do
3129 {
3130 p=l-1; // start at the end of the string
3131 while (p>=0 && count>=0)
3132 {
3133 char c=result.at(p);
3134 switch (c)
3135 {
3136 case ':':
3137 // only exit in the case of ::
3138 //printf("stripScope(%s)=%s\n",name,qPrint(result.right(l-p-1)));
3139 if (p>0 && result.at(p-1)==':' && (count==0 || skipBracket))
3140 {
3141 return result.right(l-p-1);
3142 }
3143 p--;
3144 break;
3145 case '>':
3146 if (skipBracket) // we don't care about brackets
3147 {
3148 p--;
3149 }
3150 else // count open/close brackets
3151 {
3152 if (p>0 && result.at(p-1)=='>') // skip >> operator
3153 {
3154 p-=2;
3155 break;
3156 }
3157 count=1;
3158 //printf("pos < = %d\n",p);
3159 p--;
3160 bool foundMatch=false;
3161 while (p>=0 && !foundMatch)
3162 {
3163 c=result.at(p--);
3164 switch (c)
3165 {
3166 case ')':
3167 round++;
3168 break;
3169 case '(':
3170 round--;
3171 break;
3172 case '>': // ignore > inside (...) to support e.g. (sizeof(T)>0) inside template parameters
3173 if (round==0) count++;
3174 break;
3175 case '<':
3176 if (round==0)
3177 {
3178 if (p>0)
3179 {
3180 if (result.at(p-1) == '<') // skip << operator
3181 {
3182 p--;
3183 break;
3184 }
3185 }
3186 count--;
3187 foundMatch = count==0;
3188 }
3189 break;
3190 default:
3191 //printf("c=%c count=%d\n",c,count);
3192 break;
3193 }
3194 }
3195 }
3196 //printf("pos > = %d\n",p+1);
3197 break;
3198 default:
3199 p--;
3200 }
3201 }
3202 done = count==0 || skipBracket; // reparse if brackets do not match
3203 skipBracket=true;
3204 }
3205 while (!done); // if < > unbalanced repeat ignoring them
3206 //printf("stripScope(%s)=%s\n",name,name);
3207 return name;
3208}

References DString::at(), DString::length(), and DString::right().

Referenced by DotClassGraph::addClass(), DocRef::DocRef(), generateJSLink(), getCanonicalTypeForIdentifier(), DefinitionImpl::Private::init(), DiagramItem::label(), NamespaceDefImpl::writeBriefDescription(), and ClassDefImpl::writeIncludeFilesForSlice().

◆ stripTemplateSpecifiersFromScope()

DString stripTemplateSpecifiersFromScope ( const DString & fullName,
bool parentOnly,
DString * pLastScopeStripped,
DString scopeName,
bool allowArtificial )

Strips template specifiers from scope fullName, except those that make up specialized classes. The switch parentOnly determines whether or not a template "at the end" of a scope should be considered, e.g. with parentOnly is true, A<T>::B<S> will try to strip <T> and not <S>, while parentOnly is false will strip both unless A<T> or B<S> are specialized template classes.

Definition at line 3695 of file util.cpp.

3700{
3701 //printf("stripTemplateSpecifiersFromScope(name=%s,scopeName=%s)\n",qPrint(fullName),qPrint(scopeName));
3702 size_t i=fullName.find('<');
3703 if (i==DString::npos) return fullName;
3704 DString result;
3705 size_t p=0;
3706 size_t l=fullName.length();
3707 while (i!=DString::npos)
3708 {
3709 //printf("1:result+=%s\n",qPrint(fullName.mid(p,i-p)));
3710 size_t e=i+1;
3711 int count=1;
3712 int round=0;
3713 while (e<l && count>0)
3714 {
3715 char c=fullName.at(e++);
3716 switch (c)
3717 {
3718 case '(': round++; break;
3719 case ')': if (round>0) round--; break;
3720 case '<': if (round==0) count++; break;
3721 case '>': if (round==0) count--; break;
3722 default:
3723 break;
3724 }
3725 }
3726 size_t si = fullName.find("::",e);
3727
3728 if (parentOnly && si==DString::npos) break;
3729 // we only do the parent scope, so we stop here if needed
3730
3731 result+=fullName.mid(p,i-p);
3732 //printf(" trying %s\n",qPrint(mergeScopes(scopeName,result+fullName.mid(i,e-i))));
3733 ClassDef *cd = getClass(mergeScopes(scopeName,result+fullName.mid(i,e-i)));
3734 if (cd!=nullptr && (allowArtificial || !cd->isArtificial()))
3735 {
3736 result+=fullName.mid(i,e-i);
3737 //printf(" 2:result+=%s\n",qPrint(fullName.mid(i,e-i-1)));
3738 }
3739 else if (pLastScopeStripped)
3740 {
3741 //printf(" last stripped scope '%s'\n",qPrint(fullName.mid(i,e-i)));
3742 *pLastScopeStripped=fullName.mid(i,e-i);
3743 }
3744 p=e;
3745 i=fullName.find('<',p);
3746 }
3747 result+=fullName.right(l-p);
3748 //printf("3:result+=%s\n",qPrint(fullName.right(l-p)));
3749 //printf("end result=%s\n",qPrint(result));
3750 return result;
3751}
virtual bool isArtificial() const =0
DString mergeScopes(const DString &leftScope, const DString &rightScope)
Definition util.cpp:3762

References DString::at(), DString::find(), getClass(), Definition::isArtificial(), DString::length(), mergeScopes(), DString::mid(), DString::npos, and DString::right().

Referenced by addClassToContext(), addMemberFunction(), addVariable(), buildFunctionList(), computeTemplateClassRelations(), extractClassName(), findMember(), findScopeFromQualifiedName(), findUsingDeclImports(), getCanonicalTypeForIdentifier(), SymbolResolver::Private::getResolvedSymbolRec(), SymbolResolver::Private::getResolvedTypeRec(), SymbolResolver::Private::newResolveTypedef(), and resolveLink().

◆ substituteKeywords()

DString substituteKeywords ( const DString & file,
const DString & s,
const KeywordSubstitutionList & keywords )

Definition at line 2503 of file util.cpp.

2504{
2505 std::string substRes;
2506 int line = 1;
2507 const char *p = s.data();
2508 if (p)
2509 {
2510 // reserve some room for expansion
2511 substRes.reserve(s.length()+1024);
2512 char c = 0;
2513 while ((c=*p))
2514 {
2515 bool found = false;
2516 if (c=='$')
2517 {
2518 for (const auto &kw : keywords)
2519 {
2520 size_t keyLen = dstrlen(kw.keyword);
2521 if (dstrncmp(p,kw.keyword,keyLen)==0)
2522 {
2523 const char *startArg = p+keyLen;
2524 bool expectParam = std::holds_alternative<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
2525 //printf("%s: expectParam=%d *startArg=%c\n",kw.keyword,expectParam,*startArg);
2526 if (expectParam && *startArg=='(') // $key(value)
2527 {
2528 size_t j=1;
2529 const char *endArg = nullptr;
2530 while ((c=*(startArg+j)) && c!=')' && c!='\n' && c!=0) j++;
2531 if (c==')') endArg=startArg+j;
2532 if (endArg)
2533 {
2534 DString value = DString(startArg+1).left(endArg-startArg-1);
2535 auto &&getValue = std::get<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
2536 substRes+=getValue(value).str();
2537 p=endArg+1;
2538 //printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue(value)));
2539 }
2540 else
2541 {
2542 //printf("missing argument\n");
2543 warn(file,line,"Missing argument for '{}'",kw.keyword);
2544 p+=keyLen;
2545 }
2546 }
2547 else if (!expectParam) // $key
2548 {
2549 auto &&getValue = std::get<KeywordSubstitution::GetValue>(kw.getValueVariant);
2550 substRes+=getValue().str();
2551 //printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue()));
2552 p+=keyLen;
2553 }
2554 else
2555 {
2556 //printf("%s %d Expected arguments, none specified '%s'\n",qPrint(file), line, qPrint(kw.keyword));
2557 warn(file,line,"Expected arguments for '{}' but none were specified",kw.keyword);
2558 p+=keyLen;
2559 }
2560 found = true;
2561 break;
2562 }
2563 }
2564 }
2565 if (!found) // copy
2566 {
2567 if (c=='\n') line++;
2568 substRes+=c;
2569 p++;
2570 }
2571 }
2572 }
2573 return substRes;
2574}

References DString::data(), dstrlen(), dstrncmp(), DString::left(), DString::length(), and warn.

Referenced by substituteHtmlKeywords(), and substituteLatexKeywords().

◆ substituteTemplateArgumentsInString()

DString substituteTemplateArgumentsInString ( const DString & name,
const ArgumentList & formalArgs,
const ArgumentList * actualArgs )

Substitutes any occurrence of a formal argument from argument list formalArgs in name by the corresponding actual argument in argument list actualArgs. The result after substitution is returned as a string. The argument name is used to prevent recursive substitution.

Definition at line 3533 of file util.cpp.

3537{
3538 AUTO_TRACE("name={} formalArgs={} actualArgs={}",nm,argListToString(formalArgs),actualArgs ? argListToString(*actualArgs) : DString());
3539 if (formalArgs.empty()) return nm;
3540 DString result;
3541
3542 static const reg::Ex re(R"(\a\w*)");
3543 std::string name = nm.str();
3544 reg::Iterator it(name,re);
3546 size_t p=0;
3547
3548 for (; it!=end ; ++it)
3549 {
3550 const auto &match = *it;
3551 size_t i = match.position();
3552 size_t l = match.length();
3553 if (i>p) result += name.substr(p,i-p);
3554 DString n(match.str());
3556 if (actualArgs)
3557 {
3558 actIt = actualArgs->begin();
3559 }
3560 //printf(": name=%s\n",qPrint(name));
3561
3562 // if n is a template argument, then we substitute it
3563 // for its template instance argument.
3564 bool found=false;
3565 for (auto formIt = formalArgs.begin();
3566 formIt!=formalArgs.end() && !found;
3567 ++formIt
3568 )
3569 {
3570 Argument formArg = *formIt;
3571 Argument actArg;
3572 if (actualArgs && actIt!=actualArgs->end())
3573 {
3574 actArg = *actIt;
3575 }
3576 if (formArg.type.startsWith("class ") && formArg.name.empty())
3577 {
3578 formArg.name = formArg.type.mid(6);
3579 formArg.type = "class";
3580 }
3581 else if (formArg.type.startsWith("typename ") && formArg.name.empty())
3582 {
3583 formArg.name = formArg.type.mid(9);
3584 formArg.type = "typename";
3585 }
3586 else if (formArg.type.startsWith("class...")) // match 'class... name' to 'name...'
3587 {
3588 formArg.name += "...";
3589 formArg.type = formArg.type.left(5)+formArg.type.mid(8);
3590 }
3591 else if (formArg.type.startsWith("typename...")) // match 'typename... name' to 'name...'
3592 {
3593 formArg.name += "...";
3594 formArg.type = formArg.type.left(8)+formArg.type.mid(11);
3595 }
3596 //printf(": n=%s formArg->type='%s' formArg->name='%s' formArg->defval='%s' actArg->type='%s' actArg->name='%s' \n",
3597 // qPrint(n),qPrint(formArg.type),qPrint(formArg.name),qPrint(formArg.defval),qPrint(actArg.type),qPrint(actArg.name));
3598 if (formArg.type=="class" || formArg.type=="typename" || formArg.type.startsWith("template"))
3599 {
3600 if (formArg.name==n && actualArgs && actIt!=actualArgs->end() && !actArg.type.empty()) // base class is a template argument
3601 {
3602 static constexpr auto hasRecursion = [](const DString &prefix,const DString &nameArg,const DString &subst) -> bool
3603 {
3604 size_t ii=0;
3605 size_t pp=0;
3606
3607 ii = subst.find('<');
3608 //printf("prefix='%s' subst='%s'\n",qPrint(prefix.mid(prefix.length()-ii-2,ii+1)),qPrint(subst.left(ii+1)));
3609 if (ii!=DString::npos && prefix.length()>=ii+2 && prefix.mid(prefix.length()-ii-2,ii+1)==subst.left(ii+1))
3610 {
3611 return true; // don't replace 'A< ' with 'A< A<...', see issue #10951
3612 }
3613
3614 while ((ii=subst.find(nameArg,pp))!=DString::npos)
3615 {
3616 bool beforeNonWord = ii==0 || !isId(subst.at(ii-1));
3617 bool afterNonWord = subst.length()==ii+nameArg.length() || !isId(subst.at(ii+nameArg.length()));
3618 if (beforeNonWord && afterNonWord)
3619 {
3620 return true; // if nameArg=='A' then subst=='A::Z' or 'S<A>' or 'Z::A' should return true, but 'AA::ZZ' or 'BAH' should not match
3621 }
3622 pp=ii+nameArg.length();
3623 }
3624 return false;
3625 };
3626 // replace formal argument with the actual argument of the instance
3627 AUTO_TRACE_ADD("result={} n={} type={} hasRecursion={}",result,n,actArg.type,hasRecursion(result,n,actArg.type));
3628 if (!hasRecursion(result,n,actArg.type))
3629 // the scope guard is to prevent recursive lockup for
3630 // template<class A> class C : public<A::T>,
3631 // where A::T would become A::T::T here,
3632 // since n==A and actArg->type==A::T
3633 // see bug595833 for an example
3634 //
3635 // Also prevent recursive substitution if n is part of actArg.type, i.e.
3636 // n='A' in argType='S< A >' would produce 'S< S< A > >'
3637 {
3638 if (actArg.name.empty())
3639 {
3640 result += actArg.type;
3641 }
3642 else
3643 // for case where the actual arg is something like "unsigned int"
3644 // the "int" part is in actArg->name.
3645 {
3646 result += actArg.type+" "+actArg.name;
3647 }
3648 found=true;
3649 }
3650 }
3651 else if (formArg.name==n &&
3652 (actualArgs==nullptr || actIt==actualArgs->end()) &&
3653 !formArg.defval.empty() &&
3654 formArg.defval!=nm /* to prevent recursion */
3655 )
3656 {
3657 result += substituteTemplateArgumentsInString(formArg.defval,formalArgs,actualArgs);
3658 found=true;
3659 }
3660 }
3661 else if (formArg.name==n &&
3662 (actualArgs==nullptr || actIt==actualArgs->end()) &&
3663 !formArg.defval.empty() &&
3664 formArg.defval!=nm /* to prevent recursion */
3665 )
3666 {
3667 result += substituteTemplateArgumentsInString(formArg.defval,formalArgs,actualArgs);
3668 found=true;
3669 }
3670 if (actualArgs && actIt!=actualArgs->end())
3671 {
3672 actIt++;
3673 }
3674 }
3675 if (!found)
3676 {
3677 result += n;
3678 }
3679 p=i+l;
3680 }
3681 result+=name.substr(p);
3682 result=result.simplifyWhiteSpace();
3683 AUTO_TRACE_EXIT("result={}",result);
3684 return result.stripWhiteSpace();
3685}
typename Vec::const_iterator const_iterator
Definition arguments.h:70
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple internal white...
Definition dstring.cpp:127
DString substituteTemplateArgumentsInString(const DString &nm, const ArgumentList &formalArgs, const ArgumentList *actualArgs)
Definition util.cpp:3533

References argListToString(), AUTO_TRACE, AUTO_TRACE_ADD, AUTO_TRACE_EXIT, ArgumentList::begin(), Argument::defval, ArgumentList::empty(), DString::empty(), ArgumentList::end(), end(), isId(), DString::left(), DString::mid(), Argument::name, DString::npos, prefix, DString::simplifyWhiteSpace(), DString::startsWith(), DString::str(), DString::stripWhiteSpace(), substituteTemplateArgumentsInString(), and Argument::type.

Referenced by computeMemberRelationsForBaseClass(), computeTemplateClassRelations(), MemberDefImpl::createTemplateInstanceMember(), findBaseClassesForClass(), findUsedClassesForClass(), SymbolResolver::Private::getResolvedSymbol(), SymbolResolver::Private::newResolveTypedef(), and substituteTemplateArgumentsInString().

◆ tempArgListToString()

DString tempArgListToString ( const ArgumentList & al,
SrcLangExt lang,
bool includeDefaults = true )

Returns a string representation of the template parameter list al. The lang parameter is used to determine the correct syntax for the template parameters. If includeDefaults is true then default values are included in the string representation.

Definition at line 908 of file util.cpp.

909{
910 DString result;
911 if (al.empty()) return result;
912 result="<";
913 bool first=true;
914 for (const auto &a : al)
915 {
916 if (a.defval.empty() || includeDefault)
917 {
918 if (!first) result+=", ";
919 if (!a.name.empty()) // add template argument name
920 {
921 if (lang==SrcLangExt::Java || lang==SrcLangExt::CSharp)
922 {
923 result+=a.type+" ";
924 }
925 result+=a.name;
926 }
927 else // extract name from type
928 {
929 int i = static_cast<int>(a.type.length())-1;
930 while (i>=0 && isId(a.type.at(i))) i--;
931 if (i>0)
932 {
933 result+=a.type.right(a.type.length()-i-1);
934 if (a.type.find("...")!=DString::npos)
935 {
936 result+="...";
937 }
938 }
939 else // nothing found -> take whole name
940 {
941 result+=a.type;
942 }
943 }
944 if (!a.typeConstraint.empty() && lang==SrcLangExt::Java)
945 {
946 result+=" extends "; // TODO: now Java specific, C# has where...
947 result+=a.typeConstraint;
948 }
949 first=false;
950 }
951 }
952 result+=">";
953 return removeRedundantWhiteSpace(result);
954}

References ArgumentList::empty(), isId(), DString::npos, removeRedundantWhiteSpace(), and DString::right().

Referenced by addMemberFunction(), ClassDefImpl::className(), findTemplateInstanceRelation(), makeQualifiedNameWithTemplateParameters(), searchTemplateSpecs(), and writeDefArgumentList().

◆ unescapeCharsInString()

DString unescapeCharsInString ( const DString & s)

Definition at line 2784 of file util.cpp.

2785{
2786 if (s.empty()) return s;
2787 bool caseSenseNames = useCaseSenseNames();
2788 DString result;
2789 result.reserve(s.length());
2790 const char *p = s.data();
2791 if (p)
2792 {
2793 char c = 0;
2794 while ((c=*p++))
2795 {
2796 if (c=='_') // 2 or 3 character escape
2797 {
2798 switch (*p)
2799 {
2800 case '_': result+=c; p++; break; // __ -> '_'
2801 case '1': result+=':'; p++; break; // _1 -> ':'
2802 case '2': result+='/'; p++; break; // _2 -> '/'
2803 case '3': result+='<'; p++; break; // _3 -> '<'
2804 case '4': result+='>'; p++; break; // _4 -> '>'
2805 case '5': result+='*'; p++; break; // _5 -> '*'
2806 case '6': result+='&'; p++; break; // _6 -> '&'
2807 case '7': result+='|'; p++; break; // _7 -> '|'
2808 case '8': result+='.'; p++; break; // _8 -> '.'
2809 case '9': result+='!'; p++; break; // _9 -> '!'
2810 case '0': // 3 character escape
2811 switch (*(p+1))
2812 {
2813 case '0': result+=','; p+=2; break; // _00 -> ','
2814 case '1': result+=' '; p+=2; break; // _01 -> ' '
2815 case '2': result+='{'; p+=2; break; // _02 -> '{'
2816 case '3': result+='}'; p+=2; break; // _03 -> '}'
2817 case '4': result+='?'; p+=2; break; // _04 -> '?'
2818 case '5': result+='^'; p+=2; break; // _05 -> '^'
2819 case '6': result+='%'; p+=2; break; // _06 -> '%'
2820 case '7': result+='('; p+=2; break; // _07 -> '('
2821 case '8': result+=')'; p+=2; break; // _08 -> ')'
2822 case '9': result+='+'; p+=2; break; // _09 -> '+'
2823 case 'a': result+='='; p+=2; break; // _0a -> '='
2824 case 'b': result+='$'; p+=2; break; // _0b -> '$'
2825 case 'c': result+='\\'; p+=2; break;// _0c -> '\'
2826 case 'd': result+='@'; p+=2; break; // _0d -> '@'
2827 case 'e': result+=']'; p+=2; break; // _0e -> ']'
2828 case 'f': result+='['; p+=2; break; // _0f -> '['
2829 case 'g': result+='#'; p+=2; break; // _0g -> '#'
2830 case 'h': result+='"'; p+=2; break; // _0h -> '"'
2831 case 'i': result+='~'; p+=2; break; // _0i -> '~'
2832 case 'j': result+='\''; p+=2; break;// _0j -> '\'
2833 case 'k': result+=';'; p+=2; break; // _0k -> ';'
2834 case 'l': result+='`'; p+=2; break; // _0l -> '`'
2835 default: // unknown escape, just pass underscore character as-is
2836 result+=c;
2837 break;
2838 }
2839 break;
2840 default:
2841 if (!caseSenseNames && c>='a' && c<='z') // lower to upper case escape, _a -> 'A'
2842 {
2843 result+=static_cast<char>(toupper(*p));
2844 p++;
2845 }
2846 else // unknown escape, pass underscore character as-is
2847 {
2848 result+=c;
2849 }
2850 break;
2851 }
2852 }
2853 else // normal character; pass as is
2854 {
2855 result+=c;
2856 }
2857 }
2858 }
2859 return result;
2860}

References DString::data(), DString::empty(), DString::length(), DString::reserve(), and useCaseSenseNames().

◆ updateLanguageMapping()

bool updateLanguageMapping ( const DString & extension,
const DString & parser )

Definition at line 4072 of file util.cpp.

4073{
4074 DString langName = language.lower();
4075 auto it1 = std::find_if(g_lang2extMap.begin(),g_lang2extMap.end(),
4076 [&langName](const auto &info) { return info.langName==langName; });
4077 if (it1 == g_lang2extMap.end()) return false;
4078
4079 // found the language
4080 SrcLangExt parserId = it1->parserId;
4081 DString extName = extension.lower();
4082 if (extName.empty()) return false;
4083 if (extName.at(0)!='.') extName.prepend(".");
4084 auto it2 = g_extLookup.find(extName.str());
4085 if (it2!=g_extLookup.end())
4086 {
4087 g_extLookup.erase(it2); // language was already register for this ext
4088 }
4089 //printf("registering extension %s\n",qPrint(extName));
4090 g_extLookup.emplace(extName.str(),parserId);
4091 if (!Doxygen::parserManager->registerExtension(extName,it1->parserName))
4092 {
4093 err("Failed to assign extension {} to parser {} for language {}\n",
4094 extName.data(),it1->parserName,language);
4095 }
4096 else
4097 {
4098 //msg("Registered extension {} to language parser {}...\n",
4099 // extName,language);
4100 }
4101 return true;
4102}
static ParserManager * parserManager
Definition doxygen.h:122
SrcLangExt
Definition types.h:207

References DString::at(), DString::data(), DString::empty(), err, g_extLookup, g_lang2extMap, DString::lower(), Doxygen::parserManager, DString::prepend(), and DString::str().

Referenced by addCodeOnlyMappings(), adjustConfiguration(), and initDefaultExtensionMapping().

◆ useCaseSenseNames()

bool useCaseSenseNames ( )

Returns true if the names of the symbols can be case sensitive.

Definition at line 2688 of file util.cpp.

2689{
2690 auto caseSenseNames = Config_getEnum(CASE_SENSE_NAMES);
2691
2692 if (caseSenseNames == CASE_SENSE_NAMES_t::YES) return true;
2693 else if (caseSenseNames == CASE_SENSE_NAMES_t::NO) return false;
2695}
#define Config_getEnum(name)
Definition config.h:35
bool fileSystemIsCaseSensitive()
Definition portable.cpp:486

References Config_getEnum, and Portable::fileSystemIsCaseSensitive().

Referenced by checkAndOpenFile(), escapeCharsInString(), getEncoding(), readDir(), FileNameFn::searchKey(), and unescapeCharsInString().

◆ writeExamples()

void writeExamples ( OutputList & ol,
const ExampleList & el )

Definition at line 809 of file util.cpp.

810{
811 auto replaceFunc = [&list,&ol](size_t entryIndex)
812 {
813 const auto &e = list[entryIndex];
818 // link for Html / man
819 //printf("writeObjectLink(file=%s)\n",qPrint(e->file));
820 ol.writeObjectLink(DString(),e.file,e.anchor,e.name);
822
826 // link for Latex / pdf with anchor because the sources
827 // are not hyperlinked (not possible with a verbatim environment).
828 ol.writeObjectLink(DString(),e.file,DString(),e.name);
830 };
831
832 writeMarkerList(ol, theTranslator->trWriteList(static_cast<int>(list.size())).str(), list.size(), replaceFunc);
833
834 ol.writeString(".");
835}
void disable(OutputType o)
void writeObjectLink(const DString &ref, const DString &file, const DString &anchor, const DString &name)
Definition outputlist.h:435
void writeString(const DString &text)
Definition outputlist.h:407
void pushGeneratorState()
void popGeneratorState()
virtual DString trWriteList(int numEntries)=0
Translator * theTranslator
Definition language.cpp:76
void writeMarkerList(OutputList &ol, const std::string &markerText, size_t numMarkers, std::function< void(size_t)> replaceFunc)
Definition util.cpp:758

References OutputList::disable(), Docbook, Html, Latex, Man, OutputList::popGeneratorState(), OutputList::pushGeneratorState(), RTF, DString::str(), theTranslator, Translator::trWriteList(), writeMarkerList(), OutputList::writeObjectLink(), and OutputList::writeString().

Referenced by MemberDefImpl::_writeExamples(), and ClassDefImpl::writeDetailedDocumentationBody().

◆ writeInlineGraph()

DString writeInlineGraph ( const DString & baseName,
const DString & extension,
const DString & content,
bool & exists )

Thread-safe function to write a string representing an inline graph to a file. The contents will be used to create a hash that will be used to make the name unique.

Parameters
[in]baseNamethe base name of the file to write including path.
[in]extensionthe file extension to use.
[in]contentthe data to write to the file
[out]existsis set to true if the file was already written before.
Returns
the name of the file written or an empty string in case of an error.

Definition at line 5410 of file util.cpp.

5411{
5412 DString fileName = baseName + md5str(content.view()) + extension;
5413 { // ==== start atomic section
5414 std::lock_guard lock(writeFileContents_lock);
5415 auto it=writeFileContents_set.find(fileName.str());
5416 exists = it!=writeFileContents_set.end();
5417 if (!exists)
5418 {
5419 writeFileContents_set.insert(fileName.str());
5420 if (auto file = Portable::openOutputStream(fileName); file.is_open())
5421 {
5422 file.write( content.data(), content.length() );
5423 file.close();
5424 }
5425 else
5426 {
5427 err("Could not open file {} for writing\n",fileName);
5428 return DString();
5429 }
5430 }
5431 } // ==== end atomic section
5432 return fileName;
5433}
static std::mutex writeFileContents_lock
Definition util.cpp:5407

References DString::data(), err, DString::length(), md5str(), Portable::openOutputStream(), DString::str(), DString::view(), writeFileContents_lock, and writeFileContents_set.

Referenced by DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), DocbookDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), HtmlDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), LatexDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), RTFDocVisitor::operator()(), and RTFDocVisitor::operator()().

◆ writeMarkerList() [1/2]

DString writeMarkerList ( const std::string & markerText,
size_t numMarkers,
std::function< DString(size_t)> replaceFunc )

Definition at line 781 of file util.cpp.

783{
784 DString result;
785 static const reg::Ex marker(R"(@(\d+))");
786 reg::Iterator it(markerText,marker);
788 size_t index=0;
789 for ( ; it!=end ; ++it)
790 {
791 const auto &match = *it;
792 size_t newIndex = match.position();
793 size_t matchLen = match.length();
794 result += markerText.substr(index,newIndex-index);
795 unsigned long entryIndex = std::stoul(match[1].str());
796 if (entryIndex<static_cast<unsigned long>(numMarkers))
797 {
798 result+=replaceFunc(entryIndex);
799 }
800 index=newIndex+matchLen;
801 }
802 if (index<markerText.size())
803 {
804 result += markerText.substr(index);
805 }
806 return result;
807}

References end(), and DString::substr().

◆ writeMarkerList() [2/2]

void writeMarkerList ( OutputList & ol,
const std::string & markerText,
size_t numMarkers,
std::function< void(size_t)> replaceFunc )

Definition at line 758 of file util.cpp.

760{
761 static const reg::Ex marker(R"(@(\d+))");
762 reg::Iterator it(markerText,marker);
764 size_t index=0;
765 for ( ; it!=end ; ++it)
766 {
767 const auto &match = *it;
768 size_t newIndex = match.position();
769 size_t matchLen = match.length();
770 ol.parseText(markerText.substr(index,newIndex-index));
771 unsigned long entryIndex = std::stoul(match[1].str());
772 if (entryIndex<static_cast<unsigned long>(numMarkers))
773 {
774 replaceFunc(entryIndex);
775 }
776 index=newIndex+matchLen;
777 }
778 ol.parseText(markerText.substr(index));
779}
void parseText(const DString &textStr)

References end(), and OutputList::parseText().

Referenced by MemberDefImpl::_writeReimplementedBy(), DefinitionImpl::_writeSourceRefList(), RequirementManager::generatePage(), writeExamples(), ClassDefImpl::writeInheritanceGraph(), and DefinitionImpl::writeRequirementRefs().

◆ writeTypeConstraints()

void writeTypeConstraints ( OutputList & ol,
const Definition * d,
const ArgumentList & al )

Definition at line 4292 of file util.cpp.

4293{
4294 if (al.empty()) return;
4296 for (const Argument &a : al)
4297 {
4299 ol.parseText(a.name);
4300 ol.endConstraintParam();
4302 linkifyText(TextGeneratorOLImpl(ol),a.type,LinkifyTextOptions().setScope(d));
4303 ol.endConstraintType();
4305 ol.generateDoc(d->docFile(),
4306 d->docLine(),
4307 d,
4308 nullptr,
4309 a.docs,
4310 DocOptions()
4311 .setIndexWords(true));
4312 ol.endConstraintDocs();
4313 }
4314 ol.endConstraintList();
4315}
virtual int docLine() const =0
virtual DString docFile() const =0
void endConstraintType()
Definition outputlist.h:710
void endConstraintList()
Definition outputlist.h:716
void startConstraintList(const DString &header)
Definition outputlist.h:702
void startConstraintParam()
Definition outputlist.h:704
void startConstraintDocs()
Definition outputlist.h:712
void startConstraintType()
Definition outputlist.h:708
void endConstraintDocs()
Definition outputlist.h:714
void endConstraintParam()
Definition outputlist.h:706
void generateDoc(const DString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const DString &docStr, const DocOptions &options)
Implements TextGeneratorIntf for an OutputDocInterface stream.
Definition outputlist.h:786
virtual DString trTypeConstraints()=0
void linkifyText(const TextGeneratorIntf &out, const DString &text, const LinkifyTextOptions &options)
Helper class to pass options when calling OutputList::generateDoc().
Definition docoptions.h:24

References Definition::docFile(), Definition::docLine(), ArgumentList::empty(), OutputList::endConstraintDocs(), OutputList::endConstraintList(), OutputList::endConstraintParam(), OutputList::endConstraintType(), OutputList::generateDoc(), linkifyText(), OutputList::parseText(), OutputList::startConstraintDocs(), OutputList::startConstraintList(), OutputList::startConstraintParam(), OutputList::startConstraintType(), theTranslator, and Translator::trTypeConstraints().

Referenced by MemberDefImpl::_writeTypeConstraints(), and ClassDefImpl::writeDetailedDocumentationBody().