1 /******************************************************************************
3 * $Id: util.h,v 1.49 2001/03/19 19:27:42 root Exp $
5 * Copyright (C) 1997-2012 by Dimitri van Heesch.
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation under the terms of the GNU General Public License is hereby
9 * granted. No representations are made about the suitability of this software
10 * for any purpose. It is provided "as is" without express or implied warranty.
11 * See the GNU General Public License for more details.
13 * Documents produced by Doxygen are derivative works derived from the
14 * input used in their production; they are not affected by this license.
22 * \brief A bunch of utility functions.
27 #include <qtextstream.h>
32 //--------------------------------------------------------------------
41 class OutputDocInterface;
49 class MemberGroupSDict;
51 class MemberNameInfoSDict;
62 //--------------------------------------------------------------------
64 /** Abstract interface for a hyperlinked text fragment. */
65 class TextGeneratorIntf
68 virtual ~TextGeneratorIntf() {}
69 virtual void writeString(const char *,bool) const = 0;
70 virtual void writeBreak(int indent) const = 0;
71 virtual void writeLink(const char *extRef,const char *file,
72 const char *anchor,const char *text
76 /** Implements TextGeneratorIntf for an OutputDocInterface stream. */
77 class TextGeneratorOLImpl : public TextGeneratorIntf
80 virtual ~TextGeneratorOLImpl() {}
81 TextGeneratorOLImpl(OutputDocInterface &od);
82 void writeString(const char *s,bool keepSpaces) const;
83 void writeBreak(int indent) const;
84 void writeLink(const char *extRef,const char *file,
85 const char *anchor,const char *text
88 OutputDocInterface &m_od;
91 //--------------------------------------------------------------------
93 QCString langToString(SrcLangExt lang);
94 QCString getLanguageSpecificSeparator(SrcLangExt lang,bool classScope=FALSE);
96 //--------------------------------------------------------------------
98 void linkifyText(const TextGeneratorIntf &ol,
103 bool autoBreak=FALSE,
105 bool keepSpaces=FALSE,
109 void setAnchors(ClassDef *cd,char id,MemberList *ml,int groupId=-1);
111 QCString fileToString(const char *name,bool filter=FALSE,bool isSourceCode=FALSE);
113 QCString dateToString(bool);
115 bool getDefs(const QCString &scopeName,
116 const QCString &memberName,
123 bool forceEmptyScope=FALSE,
124 FileDef *currentFile=0,
126 const char *forceTagFile=0
129 QCString getFileFilter(const char* name,bool isSourceCode);
131 bool resolveRef(/* in */ const char *scName,
132 /* in */ const char *name,
133 /* in */ bool inSeeBlock,
134 /* out */ Definition **resContext,
135 /* out */ MemberDef **resMember,
136 /* in */ bool lookForSpecializations = TRUE,
137 /* in */ FileDef *currentFile = 0,
138 /* in */ bool checkScope = FALSE
141 bool resolveLink(/* in */ const char *scName,
142 /* in */ const char *lr,
143 /* in */ bool inSeeBlock,
144 /* out */ Definition **resContext,
145 /* out */ QCString &resAnchor
148 //bool generateRef(OutputDocInterface &od,const char *,
149 // const char *,bool inSeeBlock,const char * =0);
151 bool generateLink(OutputDocInterface &od,const char *,
152 const char *,bool inSeeBlock,const char *);
154 void generateFileRef(OutputDocInterface &od,const char *,
155 const char *linkTxt=0);
157 void writePageRef(OutputDocInterface &od,const char *cn,const char *mn);
159 QCString getCanonicalTemplateSpec(Definition *d,FileDef *fs,const QCString& spec);
161 bool matchArguments2(Definition *srcScope,FileDef *srcFileScope,ArgumentList *srcAl,
162 Definition *dstScope,FileDef *dstFileScope,ArgumentList *dstAl,
166 void mergeArguments(ArgumentList *,ArgumentList *,bool forceNameOverwrite=FALSE);
168 QCString substituteClassNames(const QCString &s);
170 QCString substitute(const char *s,const char *src,const char *dst);
172 QCString clearBlock(const char *s,const char *begin,const char *end);
174 QCString selectBlock(const QCString& s,const QCString &name,bool which);
176 QCString resolveDefines(const char *n);
178 ClassDef *getClass(const char *key);
180 ClassDef *getResolvedClass(Definition *scope,
183 MemberDef **pTypeDef=0,
184 QCString *pTemplSpec=0,
185 bool mayBeUnlinkable=FALSE,
186 bool mayBeHidden=FALSE,
187 QCString *pResolvedType=0);
189 NamespaceDef *getResolvedNamespace(const char *key);
191 FileDef *findFileDef(const FileNameDict *fnDict,const char *n,
194 QCString showFileDefMatches(const FileNameDict *fnDict,const char *n);
196 int guessSection(const char *name);
198 inline bool isId(int c)
200 return c=='_' || c>=128 || c<0 || isalnum(c);
203 QCString removeRedundantWhiteSpace(const QCString &s);
205 QCString argListToString(ArgumentList *al,bool useCanonicalType=FALSE,bool showDefVals=TRUE);
207 QCString tempArgListToString(ArgumentList *al);
209 QCString generateMarker(int id);
211 void writeExample(OutputList &ol,ExampleSDict *el);
213 QCString stripAnonymousNamespaceScope(const QCString &s);
215 QCString stripFromPath(const QCString &path);
217 QCString stripFromIncludePath(const QCString &path);
219 bool rightScopeMatch(const QCString &scope, const QCString &name);
221 bool leftScopeMatch(const QCString &scope, const QCString &name);
223 QCString substituteKeywords(const QCString &s,const char *title,
224 const char *projName,const char *projNum,const char *projBrief);
226 int getPrefixIndex(const QCString &name);
228 QCString removeAnonymousScopes(const QCString &s);
230 QCString replaceAnonymousScopes(const QCString &s,const char *replacement=0);
232 void initClassHierarchy(ClassSDict *cl);
234 bool hasVisibleRoot(BaseClassList *bcl);
236 int minClassDistance(const ClassDef *cd,const ClassDef *bcd,int level=0);
237 Protection classInheritedProtectionLevel(ClassDef *cd,ClassDef *bcd,Protection prot=Public,int level=0);
239 QCString convertNameToFile(const char *name,bool allowDots=FALSE,bool allowUnderscore=FALSE);
241 void extractNamespaceName(const QCString &scopeName,
242 QCString &className,QCString &namespaceName,
243 bool allowEmptyClass=FALSE);
245 QCString insertTemplateSpecifierInScope(const QCString &scope,const QCString &templ);
247 QCString stripScope(const char *name);
249 QCString convertToHtml(const char *s,bool keepEntities=TRUE);
251 QCString convertToXML(const char *s);
253 QCString convertToJSString(const char *s);
255 QCString getOverloadDocs();
257 void addMembersToMemberGroup(/* in */ MemberList *ml,
258 /* in,out */ MemberGroupSDict **ppMemberGroupSDict,
259 /* in */ Definition *context);
261 int extractClassNameFromType(const QCString &type,int &pos,
262 QCString &name,QCString &templSpec,SrcLangExt=SrcLangExt_Unknown);
264 QCString substituteTemplateArgumentsInString(
265 const QCString &name,
266 ArgumentList *formalArgs,
267 ArgumentList *actualArgs);
269 QList<ArgumentList> *copyArgumentLists(const QList<ArgumentList> *srcLists);
271 QCString stripTemplateSpecifiersFromScope(const QCString &fullName,
272 bool parentOnly=TRUE,
273 QCString *lastScopeStripped=0);
275 QCString resolveTypeDef(Definition *d,const QCString &name,
276 Definition **typedefContext=0);
278 QCString mergeScopes(const QCString &leftScope,const QCString &rightScope);
280 int getScopeFragment(const QCString &s,int p,int *l);
282 int filterCRLF(char *buf,int len);
284 void addRefItem(const QList<ListItemInfo> *sli,const char *prefix,
286 const char *name,const char *title,const char *args);
288 PageDef *addRelatedPage(const char *name,const QCString &ptitle,
289 const QCString &doc,QList<SectionInfo> *anchors,
290 const char *fileName,int startLine,
291 const QList<ListItemInfo> *sli,
294 SrcLangExt lang=SrcLangExt_Unknown
297 QCString escapeCharsInString(const char *name,bool allowDots,bool allowUnderscore=FALSE);
299 void addGroupListToTitle(OutputList &ol,Definition *d);
301 void filterLatexString(FTextStream &t,const char *str,
302 bool insideTabbing=FALSE,
303 bool insidePre=FALSE,
304 bool insideItem=FALSE);
306 QCString rtfFormatBmkStr(const char *name);
308 QCString linkToText(SrcLangExt lang,const char *link,bool isFileName);
310 QCString stripExtension(const char *fName);
312 void replaceNamespaceAliases(QCString &scope,int i);
314 int isAccessibleFrom(Definition *scope,FileDef *fileScope,Definition *item);
316 int isAccessibleFromWithExpScope(Definition *scope,FileDef *fileScope,Definition *item,
317 const QCString &explicitScopePart);
319 int computeQualifiedIndex(const QCString &name);
321 void addDirPrefix(QCString &fileName);
323 QCString relativePathToRoot(const char *name);
325 void createSubDirs(QDir &d);
327 QCString stripPath(const char *s);
329 bool containsWord(const QCString &s,const QCString &word);
331 bool findAndRemoveWord(QCString &s,const QCString &word);
333 QCString stripLeadingAndTrailingEmptyLines(const QCString &s,int &docLine);
335 //void stringToSearchIndex(const QCString &docUrlBase,const QCString &title,
336 // const QCString &str, bool priority=FALSE,
337 // const QCString &anchor="");
339 bool updateLanguageMapping(const QCString &extension,const QCString &parser);
340 SrcLangExt getLanguageFromFileName(const QCString fileName);
341 void initDefaultExtensionMapping();
343 MemberDef *getMemberFromSymbol(Definition *scope,FileDef *fileScope,
345 bool checkIfTypedef(Definition *scope,FileDef *fileScope,const char *n);
347 ClassDef *newResolveTypedef(FileDef *fileScope,MemberDef *md,
348 MemberDef **pMemType=0,QCString *pTemplSpec=0,
349 QCString *pResolvedType=0,
350 ArgumentList *actTemplParams=0);
352 QCString parseCommentAsText(const Definition *scope,const MemberDef *member,const QCString &doc,const QCString &fileName,int lineNr);
354 QCString transcodeCharacterStringToUTF8(const QCString &input);
356 QCString recodeString(const QCString &str,const char *fromEncoding,const char *toEncoding);
358 QCString extractAliasArgs(const QCString &args,int pos);
360 int countAliasArguments(const QCString argList);
362 //QCString replaceAliasArguments(const QCString &aliasValue,const QCString &argList);
364 QCString resolveAliasCmd(const QCString aliasCmd);
365 QCString expandAlias(const QCString &aliasName,const QCString &aliasValue);
367 void writeTypeConstraints(OutputList &ol,Definition *d,ArgumentList *al);
369 QCString convertCharEntitiesToUTF8(const QCString &s);
373 bool readInputFile(const char *fileName,BufStr &inBuf);
374 QCString filterTitle(const QCString &title);
376 bool patternMatch(const QFileInfo &fi,const QStrList *patList);
378 QCString externalLinkTarget();
379 QCString externalRef(const QCString &relPath,const QCString &ref,bool href);
380 int nextUtf8CharPosition(const QCString &utf8Str,int len,int startPos);
382 /** Data associated with a HSV colored image. */
383 struct ColoredImgDataItem
386 unsigned short width;
387 unsigned short height;
388 unsigned char *content;
389 unsigned char *alpha;
392 void writeColoredImgData(const char *dir,ColoredImgDataItem data[]);
393 QCString replaceColorMarkers(const char *str);
395 bool copyFile(const QCString &src,const QCString &dest);
396 QCString extractBlock(const QCString text,const QCString marker);
398 QCString correctURL(const QCString &url,const QCString &relPath);
400 QCString processMarkup(const QCString &s);
402 bool protectionLevelVisible(Protection prot);
404 QCString stripIndentation(const QCString &s);
406 bool fileVisibleInIndex(FileDef *fd,bool &genSourceFile);