Skip to content

Commit 34ae24c

Browse files
committed
issue #11656 Comment block begin is handled inside C++ raw string literal with double quotes
1 parent 5c41a91 commit 34ae24c

File tree

9 files changed

+53
-45
lines changed

9 files changed

+53
-45
lines changed

src/code.l

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
12571257
yyextra->code->codify(QCString(yytext+i+1));
12581258
yyextra->lastStringContext=YY_START;
12591259
yyextra->inForEachExpression = FALSE;
1260-
yyextra->delimiter = yytext+i+2;
1261-
yyextra->delimiter=yyextra->delimiter.left(yyextra->delimiter.length()-1);
1260+
yyextra->delimiter = extractBeginRawStringDelimiter(yytext);
12621261
BEGIN( RawString );
12631262
}
12641263
<FuncCall,Body,MemberCall,MemberCall2,SkipInits,InlineInit,ClassVar,OldStyleArgs>\" {
@@ -1306,9 +1305,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
13061305
}
13071306
<RawString>{RAWEND} {
13081307
yyextra->code->codify(yytext);
1309-
QCString delimiter(yytext+1);
1310-
delimiter=delimiter.left(delimiter.length()-1);
1311-
if (delimiter==yyextra->delimiter)
1308+
if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
13121309
{
13131310
BEGIN( yyextra->lastStringContext );
13141311
}

src/commentcnv.l

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct commentcnvYY_state
141141
std::vector<std::string> expandedAliases;
142142
QCString snippetFileName;
143143
QCString snippetName;
144+
QCString delimiter;
144145
};
145146

146147
[[maybe_unused]] static const char *stateToString(int state);
@@ -190,6 +191,7 @@ MAILADDR ("mailto:")?[a-z_A-Z0-9\x80-\xff.+-]+"@"[a-z_A-Z0-9\x80-\xff-]+("."[a
190191
%x IncludeDoc
191192
%x SnippetDoc
192193
%x SnippetDocTag
194+
%x RawString
193195
%x IncludeFile
194196

195197
CMD [\\@]
@@ -220,6 +222,9 @@ FLOAT_HEXADECIMAL {HEX_FP1}|{HEX_FP2}
220222
FLOAT_NUMBER {FLOAT_DECIMAL}|{FLOAT_HEXADECIMAL}
221223
NUMBER {INTEGER_NUMBER}|{FLOAT_NUMBER}
222224
225+
RAWBEGIN (u|U|L|u8)?R\"[^ \t\(\)\\]{0,16}"("
226+
RAWEND ")"[^ \t\(\)\\]{0,16}\"
227+
223228
FILEICHAR [a-z_A-Z0-9\x80-\xFF\\:\\\/\-\+=&#@]
224229
FILEECHAR [a-z_A-Z0-9\x80-\xFF\-\+=&#@]
225230
FILECHARS {FILEICHAR}*{FILEECHAR}+
@@ -256,6 +261,11 @@ SLASHopt [/]*
256261
if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
257262
copyToOutput(yyscanner,yytext,yyleng);
258263
}
264+
<Scan>{RAWBEGIN} {
265+
if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
266+
copyToOutput(yyscanner,yytext,yyleng);
267+
BEGIN(RawString);
268+
}
259269
<Scan>[^"'!\/\n\\#,\-=; \t@$]* { /* eat anything that is not " / , or \n */
260270
copyToOutput(yyscanner,yytext,yyleng);
261271
}
@@ -552,6 +562,17 @@ SLASHopt [/]*
552562
BEGIN(CComment);
553563
}
554564
}
565+
<RawString>{RAWEND} {
566+
copyToOutput(yyscanner,yytext,yyleng);
567+
if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
568+
{
569+
BEGIN(Scan);
570+
}
571+
}
572+
<RawString>[^)\n]+ { copyToOutput(yyscanner,yytext,yyleng); }
573+
<RawString>\n { copyToOutput(yyscanner,yytext,yyleng); }
574+
<RawString>. { copyToOutput(yyscanner,yytext,yyleng); }
575+
555576
<CComment,CNComment,ReadLine,IncludeFile>{MAILADDR} |
556577
<CComment,CNComment,ReadLine,IncludeFile>"<"{MAILADDR}">" { // Mail address, to prevent seeing e.g x@code-factory.org as start of a code block
557578
copyToOutput(yyscanner,yytext,yyleng);

src/defargs.l

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ CPPC "/\/"
173173
<ReadFuncArgDef>"'"\\."'" { yyextra->curArgDefValue+=yytext; }
174174
<ReadFuncArgDef>"'"."'" { yyextra->curArgDefValue+=yytext; }
175175
<ReadFuncArgDef>{RAWBEGIN} { yyextra->curArgDefValue+=yytext;
176-
QCString text(yytext);
177-
int i=text.find('"');
178-
yyextra->delimiter = yytext+i+1;
179-
yyextra->delimiter=yyextra->delimiter.left(yyextra->delimiter.length()-1);
176+
yyextra->delimiter = extractBeginRawStringDelimiter(yytext);
180177
BEGIN( CopyRawString );
181178
}
182179
<ReadFuncArgDef>\" {
@@ -365,9 +362,7 @@ CPPC "/\/"
365362
}
366363
<CopyRawString>{RAWEND} {
367364
yyextra->curArgDefValue+=yytext;
368-
QCString delimiter(yytext+1);
369-
delimiter=delimiter.left(delimiter.length()-1);
370-
if (delimiter==yyextra->delimiter)
365+
if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
371366
{
372367
BEGIN( ReadFuncArgDef );
373368
}

src/lexcode.l

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef yyguts_t *yyscan_t;
4141
#include "message.h"
4242
#include "debug.h"
4343
#include "searchindex.h"
44+
#include "util.h"
4445

4546
#define YY_NEVER_INTERACTIVE 1
4647
#define YY_NO_INPUT 1
@@ -535,9 +536,9 @@ NONLopt [^\n]*
535536
BEGIN( PreLineCtrl );
536537
}
537538
<SkipCurly>{B}*{RAWBEGIN} {
538-
QCString raw=QCString(yytext).stripWhiteSpace();
539-
yyextra->delimiter = raw.mid(2);
540-
yyextra->delimiter=yyextra->delimiter.left(yyextra->delimiter.length()-1);
539+
char *p = yytext;
540+
while (*p && qisspace(*p)) p++;
541+
yyextra->delimiter = extractBeginRawStringDelimiter(p);
541542
yyextra->lastRawStringContext = YY_START;
542543
yyextra->CCodeBuffer += yytext;
543544
BEGIN(RawString);
@@ -673,9 +674,7 @@ NONLopt [^\n]*
673674
}
674675
<RawString>{RAWEND} {
675676
yyextra->CCodeBuffer += yytext;
676-
QCString delimiter = yytext+1;
677-
delimiter=delimiter.left(delimiter.length()-1);
678-
if (delimiter==yyextra->delimiter)
677+
if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
679678
{
680679
BEGIN(yyextra->lastRawStringContext);
681680
}

src/lexscanner.l

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,9 @@ NONLopt [^\n]*
521521
BEGIN( PreLineCtrl );
522522
}
523523
<SkipCurly>{B}*{RAWBEGIN} {
524-
QCString raw=QCString(yytext).stripWhiteSpace();
525-
yyextra->delimiter = raw.mid(2);
526-
yyextra->delimiter=yyextra->delimiter.left(yyextra->delimiter.length()-1);
524+
char *p=yytext;
525+
while (*p && qisspace(*p)) p++;
526+
yyextra->delimiter = extractBeginRawStringDelimiter(p);
527527
yyextra->lastRawStringContext = YY_START;
528528
yyextra->cCodeBuffer += yytext;
529529
BEGIN(RawString);
@@ -651,9 +651,7 @@ NONLopt [^\n]*
651651
}
652652
<RawString>{RAWEND} {
653653
yyextra->cCodeBuffer += yytext;
654-
QCString delimiter = yytext+1;
655-
delimiter=delimiter.left(delimiter.length()-1);
656-
if (delimiter==yyextra->delimiter)
654+
if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
657655
{
658656
BEGIN(yyextra->lastRawStringContext);
659657
}

src/pre.l

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,7 @@ WSopt [ \t\r]*
555555
outputArray(yyscanner,yytext,yyleng);
556556
}
557557
<CopyLine,LexCopyLine>{RAWBEGIN} {
558-
yyextra->delimiter = yytext+2;
559-
yyextra->delimiter=yyextra->delimiter.left(yyextra->delimiter.length()-1);
558+
yyextra->delimiter = extractBeginRawStringDelimiter(yytext);
560559
outputArray(yyscanner,yytext,yyleng);
561560
BEGIN(CopyRawString);
562561
}
@@ -645,9 +644,7 @@ WSopt [ \t\r]*
645644
}
646645
<CopyRawString>{RAWEND} {
647646
outputArray(yyscanner,yytext,yyleng);
648-
QCString delimiter = yytext+1;
649-
delimiter=delimiter.left(delimiter.length()-1);
650-
if (delimiter==yyextra->delimiter)
647+
if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
651648
{
652649
BEGIN( CopyLine );
653650
}

src/scanner.l

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ static QCString stripFuncPtr(const QCString &type);
227227
static bool nameIsOperator(QCString &name);
228228
void fixArgumentListForJavaScript(ArgumentList &al);
229229
static bool startOfRequiresExpression(const QCString &req);
230-
static QCString extractBeginRawStringDelimiter(const char *str);
231-
static QCString extractEndRawStringDelimiter(const char *str);
232230

233231
// forward declarations for stateful functions
234232
static void initParser(yyscan_t yyscanner);
@@ -7698,20 +7696,6 @@ static inline int computeIndent(const char *s,int startIndent)
76987696
return col;
76997697
}
77007698

7701-
static QCString extractBeginRawStringDelimiter(const char *rawStart)
7702-
{
7703-
QCString text=rawStart;
7704-
int i = text.find('"');
7705-
assert(i!=-1);
7706-
return text.mid(i+1,text.length()-i-2); // text=...R"xyz( -> delimiter=xyz
7707-
}
7708-
7709-
static QCString extractEndRawStringDelimiter(const char *rawEnd)
7710-
{
7711-
QCString text=rawEnd;
7712-
return text.mid(1,text.length()-2); // text=)xyz" -> delimiter=xyz
7713-
}
7714-
77157699
static inline void initMethodProtection(yyscan_t yyscanner,Protection prot)
77167700
{
77177701
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;

src/util.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7448,4 +7448,18 @@ QCString demangleCSharpGenericName(const QCString &name,const QCString &templArg
74487448
return result;
74497449
}
74507450

7451+
QCString extractBeginRawStringDelimiter(const char *rawStart)
7452+
{
7453+
QCString text=rawStart;
7454+
int i = text.find('"');
7455+
assert(i!=-1);
7456+
return text.mid(i+1,text.length()-i-2); // text=...R"xyz( -> delimiter=xyz
7457+
}
7458+
7459+
QCString extractEndRawStringDelimiter(const char *rawEnd)
7460+
{
7461+
QCString text=rawEnd;
7462+
return text.mid(1,text.length()-2); // text=)xyz" -> delimiter=xyz
7463+
}
7464+
74517465

src/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,7 @@ size_t updateColumnCount(const char *s,size_t col);
483483
QCString mangleCSharpGenericName(const QCString &name);
484484
QCString demangleCSharpGenericName(const QCString &name,const QCString &templArgs);
485485

486+
QCString extractBeginRawStringDelimiter(const char *rawStart);
487+
QCString extractEndRawStringDelimiter(const char *rawEnd);
488+
486489
#endif

0 commit comments

Comments
 (0)