diff options
author | Dimitri van Heesch <dimitri@stack.nl> | 2014-10-23 18:33:19 (GMT) |
---|---|---|
committer | Dimitri van Heesch <dimitri@stack.nl> | 2014-10-23 18:33:19 (GMT) |
commit | 43edc14cd357dcb070402bccc5030507570c22a4 (patch) | |
tree | 05c76a0026b6d1fabe1c3967b041e38b9550f9f7 /src/util.cpp | |
parent | 151876a8321204bd2ec08ec6c4de38ba9fb2d034 (diff) | |
download | Doxygen-43edc14cd357dcb070402bccc5030507570c22a4.zip Doxygen-43edc14cd357dcb070402bccc5030507570c22a4.tar.gz Doxygen-43edc14cd357dcb070402bccc5030507570c22a4.tar.bz2 |
Introduce new optimized string implementation (attempt 2)
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/util.cpp b/src/util.cpp index b313b86..666fd04 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -264,8 +264,9 @@ void writePageRef(OutputDocInterface &od,const char *cn,const char *mn) */ QCString generateMarker(int id) { - QCString result; - result.sprintf("@%d",id); + const int maxMarkerStrLen = 20; + char result[maxMarkerStrLen]; + snprintf(result,maxMarkerStrLen,"@%d",id); return result; } @@ -4913,8 +4914,10 @@ FileDef *findFileDef(const FileNameDict *fnDict,const char *n,bool &ambig) ambig=FALSE; if (n==0) return 0; - QCString key; - key.sprintf("%p:",fnDict); + const int maxAddrSize = 20; + char addr[maxAddrSize]; + snprintf(addr,maxAddrSize,"%p:",fnDict); + QCString key = addr; key+=n; g_findFileDefCache.setAutoDelete(TRUE); @@ -5030,6 +5033,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.data(), 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; +} + +//---------------------------------------------------------------------- + QCString substituteKeywords(const QCString &s,const char *title, const char *projName,const char *projNum,const char *projBrief) { |