From dd88186b18613388902e4921e5203375458783b6 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Thu, 28 Dec 2017 10:01:43 +0100 Subject: Add variadic arguments support to @link and @ref, aka '...' arguments, fixes --- src/util.cpp | 35 +++++++++++++++++++++++++++++++++++ src/util.h | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index 6cc1fd3..7f87e19 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5192,6 +5192,41 @@ QCString showFileDefMatches(const FileNameDict *fnDict,const char *n) //---------------------------------------------------------------------- +/// substitute all occurrences of \a src in \a s by \a dst +QCString substitute(const QCString &s,const QCString &src,const QCString &dst) +{ + if (s.isEmpty() || src.isEmpty()) return s; + const char *p, *q; + int srcLen = src.length(); + int dstLen = dst.length(); + int resLen; + if (srcLen!=dstLen) + { + int count; + for (count=0, p=s.data(); (q=strstr(p,src))!=0; p=q+srcLen) count++; + resLen = s.length()+count*(dstLen-srcLen); + } + else // result has same size as s + { + resLen = s.length(); + } + QCString result(resLen+1); + char *r; + for (r=result.rawData(), p=s; (q=strstr(p,src))!=0; p=q+srcLen) + { + int l = (int)(q-p); + memcpy(r,p,l); + r+=l; + + if (dst) memcpy(r,dst,dstLen); + r+=dstLen; + } + qstrcpy(r,p); + //printf("substitute(%s,%s,%s)->%s\n",s,src,dst,result.data()); + return result; +} + + /// substitute all occurrences of \a src in \a s by \a dst, but skip /// each consecutive sequence of \a src where the number consecutive /// \a src matches \a skip_seq; if \a skip_seq is negative, skip any diff --git a/src/util.h b/src/util.h index 066e072..e3853b5 100644 --- a/src/util.h +++ b/src/util.h @@ -193,7 +193,8 @@ void mergeArguments(ArgumentList *,ArgumentList *,bool forceNameOverwrite=FALSE) QCString substituteClassNames(const QCString &s); -QCString substitute(const QCString &s,const QCString &src,const QCString &dst,int skip_seq = 0); +QCString substitute(const QCString &s,const QCString &src,const QCString &dst); +QCString substitute(const QCString &s,const QCString &src,const QCString &dst,int skip_seq); QCString clearBlock(const char *s,const char *begin,const char *end); -- cgit v0.12