From 539b3bbef61dc7dec8cd5987dc2dbb7a2a956a83 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Thu, 29 Oct 2020 20:46:13 +0100 Subject: Some further simplications and modernizations --- src/util.cpp | 80 +++++++++++++++++++++++------------------------------------- 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 2b53cde..69e2e0d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5942,8 +5942,7 @@ static QCString replaceAliasArguments(StringUnorderedSet &aliasesProcessed, //printf("----- replaceAliasArguments(val=[%s],args=[%s])\n",aliasValue.data(),argList.data()); // first make a list of arguments from the comma separated argument list - QList args; - args.setAutoDelete(TRUE); + std::vector args; int i,l=(int)argList.length(); int s=0; for (i=0;is) args.append(new QCString(argList.right(l-s))); + if (l>s) args.push_back(QCString(argList.right(l-s))); //printf("found %d arguments\n",args.count()); // next we look for the positions of the markers and add them to a list - QList markerList; - markerList.setAutoDelete(TRUE); + std::vector markerList; l = aliasValue.length(); + char pc='\0'; + bool insideMarkerId=false; int markerStart=0; - int markerEnd=0; + auto isDigit = [](char c) { return c>='0' && c<='9'; }; for (i=0;i0 && !(aliasValue.at(i)>='0' && aliasValue.at(i)<='9')) + char c = aliasValue.at(i); + if (insideMarkerId && !isDigit(c)) // found end of a markerId { - if (markerEnd>markerStart) // end of marker - { - int markerLen = markerEnd-markerStart; - markerList.append(new Marker(markerStart-1, // include backslash - atoi(aliasValue.mid(markerStart,markerLen)),markerLen+1)); - //printf("found marker at %d with len %d and number %d\n", - // markerStart-1,markerLen+1,atoi(aliasValue.mid(markerStart,markerLen))); - } - markerStart=0; - markerEnd=0; - } - // check for escaped command sign - if ((aliasValue.at(i) == '@' || aliasValue.at(i) == '\\') && - (((i+1)0 && aliasValue.at(i)>='0' && aliasValue.at(i)<='9') + else { - // read digit that make up the marker number - markerEnd=i+1; + if (isDigit(c) && pc=='\\') // found start of a markerId + { + insideMarkerId=true; + markerStart=i; + } + pc = c; } } - if (markerStart>0) - { - markerEnd=l; - } - if (markerStart>0 && markerEnd>markerStart) - { - int markerLen = markerEnd-markerStart; - markerList.append(new Marker(markerStart-1, // include backslash - atoi(aliasValue.mid(markerStart,markerLen)),markerLen+1)); - //printf("found marker at %d with len %d and number %d\n", - // markerStart-1,markerLen+1,atoi(aliasValue.mid(markerStart,markerLen))); - } // then we replace the markers with the corresponding arguments in one pass QCString result; int p=0; - for (i=0;i<(int)markerList.count();i++) + for (i=0;i<(int)markerList.size();i++) { - Marker *m = markerList.at(i); - result+=aliasValue.mid(p,m->pos-p); + const Marker &m = markerList.at(i); + result+=aliasValue.mid(p,m.pos-p); //printf("part before marker %d: '%s'\n",i,aliasValue.mid(p,m->pos-p).data()); - if (m->number>0 && m->number<=(int)args.count()) // valid number + if (m.number>0 && m.number<=(int)args.size()) // valid number { - result+=expandAliasRec(aliasesProcessed,*args.at(m->number-1),TRUE); + result+=expandAliasRec(aliasesProcessed,args.at(m.number-1),TRUE); //printf("marker index=%d pos=%d number=%d size=%d replacement %s\n",i,m->pos,m->number,m->size, // args.at(m->number-1)->data()); } - p=m->pos+m->size; // continue after the marker + p=m.pos+m.size; // continue after the marker } result+=aliasValue.right(l-p); // append remainder //printf("string after replacement of markers: '%s'\n",result.data()); -- cgit v0.12