@@ -34,7 +34,6 @@ typedef yyguts_t *yyscan_t;
3434#include < deque>
3535#include < string_view>
3636
37- #include " bufstr.h"
3837#include " debug.h"
3938#include " message.h"
4039#include " config.h"
@@ -50,8 +49,8 @@ typedef yyguts_t *yyscan_t;
5049#define YY_NO_INPUT 1
5150#define YY_NO_UNISTD_H 1
5251
53- #define ADDCHAR (c ) yyextra->outBuf.addChar(c)
54- #define ADDARRAY (a,s ) yyextra->outBuf.addArray (a,s)
52+ #define ADDCHAR (c ) yyextra->outBuf+=c
53+ #define ADDARRAY (a,s ) yyextra->outBuf+=std::string_view (a,s)
5554
5655struct commentcnvYY_CondCtx
5756{
@@ -71,25 +70,24 @@ struct CommentCtx
7170
7271struct commentcnv_FileState
7372{
74- commentcnv_FileState (size_t size) : fileBuf(size) {}
7573 int oldLineNr = 1 ;
7674 YY_BUFFER_STATE bufState = 0 ;
7775 QCString fileName;
7876 QCString oldFileName;
7977 QCString oldIncPrefix;
8078 int oldState = 0 ;
81- BufStr fileBuf;
82- const BufStr *oldFileBuf = nullptr ;
79+ std::string fileBuf;
80+ const std::string *oldFileBuf = nullptr ;
8381 int oldFileBufPos = 0 ;
8482 int oldIncludeCtx = 0 ;
8583};
8684
8785
8886struct commentcnvYY_state
8987{
90- commentcnvYY_state (const BufStr *i,BufStr &o) : inBuf(i), outBuf(o) {}
91- const BufStr *inBuf;
92- BufStr &outBuf;
88+ commentcnvYY_state (const std::string *i,std::string &o) : inBuf(i), outBuf(o) {}
89+ const std::string *inBuf;
90+ std::string &outBuf;
9391 int inBufPos = 0 ;
9492 int col = 0 ;
9593 int blockHeadCol = 0 ;
@@ -1484,7 +1482,7 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
14841482 return false ;
14851483 }
14861484
1487- auto fs = std::make_unique<commentcnv_FileState>(fi. size ()+ 4096 );
1485+ auto fs = std::make_unique<commentcnv_FileState>();
14881486 if (!readInputFile (absFileName,fs->fileBuf ,false ))
14891487 {
14901488 warn_doc_error (yyextra->fileName ,yyextra->lineNr ," \\ %s{doc} file '%s' could not be read" ,blockId.isEmpty ()?" include" :" snippet" ,qPrint (absFileName));
@@ -1494,7 +1492,7 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
14941492 int lineNr=1 ;
14951493 if (!blockId.isEmpty ())
14961494 {
1497- QCString incText = fs->fileBuf . data () ;
1495+ QCString incText { fs->fileBuf } ;
14981496 int count = incText.contains (blockId.data ());
14991497 if (count!=2 )
15001498 {
@@ -1505,16 +1503,12 @@ static bool readIncludeFile(yyscan_t yyscanner,const QCString &inc,const QCStrin
15051503 lineNr = lineBlock (incText, blockId);
15061504 int blockPos;
15071505 incText = extractBlock (incText, blockId, blockPos);
1508- fs->fileBuf .shrink ( 0 );
1506+ fs->fileBuf .clear ( );
15091507 if (!incText.isEmpty ())
15101508 {
1511- fs->fileBuf .addArray (incText.data (),incText. length ());
1509+ fs->fileBuf .append (incText.str ());
15121510 }
15131511 }
1514- else if (fs->fileBuf .curPos ()>0 ) // remove '\0' terminator
1515- {
1516- fs->fileBuf .shrink (fs->fileBuf .curPos ()-1 );
1517- }
15181512 QCString lineStr=" \\ ilinebr \\ ifile \" " +absFileName+" \" \\ iline " + QCString ().setNum (lineNr) + " \\ ilinebr " ;
15191513 copyToOutput (yyscanner,lineStr.data (),lineStr.length ());
15201514
@@ -1619,7 +1613,7 @@ static void replaceAliases(yyscan_t yyscanner,std::string_view s,bool replaceCom
16191613static int yyread(yyscan_t yyscanner,char *buf,int max_size)
16201614{
16211615 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1622- int bytesInBuf = static_cast<int>(yyextra->inBuf->curPos ())-yyextra->inBufPos;
1616+ int bytesInBuf = static_cast<int>(yyextra->inBuf->size ())-yyextra->inBufPos;
16231617 int bytesToCopy = std::min(max_size,bytesInBuf);
16241618 memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
16251619 yyextra->inBufPos+=bytesToCopy;
@@ -1657,7 +1651,7 @@ static void replaceComment(yyscan_t yyscanner,int offset)
16571651 * -# It replaces aliases with their definition (see ALIASES)
16581652 * -# It handles conditional sections (cond...endcond blocks)
16591653 */
1660- void convertCppComments(const BufStr &inBuf,BufStr &outBuf,const QCString &fileName)
1654+ void convertCppComments(const std::string &inBuf,std::string &outBuf,const QCString &fileName)
16611655{
16621656 yyscan_t yyscanner;
16631657 commentcnvYY_state extra(&inBuf,outBuf);
@@ -1685,7 +1679,7 @@ void convertCppComments(const BufStr &inBuf,BufStr &outBuf,const QCString &fileN
16851679 if (yyextra->lang==SrcLangExt::Fortran)
16861680 {
16871681 FortranFormat fmt = convertFileNameFortranParserCode(fileName);
1688- yyextra->isFixedForm = recognizeFixedForm(QCString(inBuf.data() ),fmt);
1682+ yyextra->isFixedForm = recognizeFixedForm(QCString(inBuf),fmt);
16891683 }
16901684
16911685 if (yyextra->lang==SrcLangExt::Markdown)
@@ -1727,9 +1721,8 @@ void convertCppComments(const BufStr &inBuf,BufStr &outBuf,const QCString &fileN
17271721 yyextra->nestingCount = 0;
17281722 if (Debug::isFlagSet(Debug::CommentCnv))
17291723 {
1730- yyextra->outBuf.at(yyextra->outBuf.curPos())=' \0' ;
1731- Debug::print (Debug::CommentCnv,0 ," -----------\n CommentCnv: %s curPos=%zu\n "
1732- " output=[\n %s]\n -----------\n " ,qPrint (fileName),yyextra->outBuf .curPos (),yyextra->outBuf .data ()
1724+ Debug::print(Debug::CommentCnv,0,"-----------\n CommentCnv: %s\n "
1725+ "output=[\n %s]\n -----------\n ",qPrint(fileName),qPrint(yyextra->outBuf)
17331726 );
17341727 }
17351728 commentcnvYYlex_destroy(yyscanner);
0 commit comments