Skip to content

Commit 1a3c4ac

Browse files
fix(markdown): fix -Wcomma warning, improve formatting
warning: possible misuse of comma operator here [-Wcomma]
1 parent 7006474 commit 1a3c4ac

File tree

1 file changed

+86
-19
lines changed

1 file changed

+86
-19
lines changed

src/markdown.cpp

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,11 @@ size_t Markdown::Private::findEmphasisChar(std::string_view data, char c, size_t
768768
if (data[i]=='`')
769769
{
770770
int snb=0;
771-
while (i<size && data[i]=='`') snb++,i++;
771+
while (i < size && data[i] == '`')
772+
{
773+
snb++;
774+
i++;
775+
}
772776

773777
// find same pattern to end the span
774778
int enb=0;
@@ -967,11 +971,13 @@ int Markdown::Private::processNmdash(std::string_view data,size_t offset)
967971
int count=1;
968972
if (i<size && data[i]=='-') // found --
969973
{
970-
count++,i++;
974+
count++;
975+
i++;
971976
}
972977
if (i<size && data[i]=='-') // found ---
973978
{
974-
count++,i++;
979+
count++;
980+
i++;
975981
}
976982
if (i<size && data[i]=='-') // found ----
977983
{
@@ -1035,7 +1041,11 @@ int Markdown::Private::processHtmlTagWrite(std::string_view data,size_t offset,b
10351041
size_t i=1;
10361042
size_t l=0;
10371043
// compute length of the tag name
1038-
while (i<size && isIdChar(data[i])) i++,l++;
1044+
while (i < size && isIdChar(data[i]))
1045+
{
1046+
i++;
1047+
l++;
1048+
}
10391049
QCString tagName(data.substr(1,i-1));
10401050
if (tagName.lower()=="pre") // found <pre> tag
10411051
{
@@ -1885,7 +1895,11 @@ int Markdown::Private::isHeaderline(std::string_view data, bool allowAdjustLevel
18851895
// test of level 1 header
18861896
if (data[i]=='=')
18871897
{
1888-
while (i<size && data[i]=='=') i++,c++;
1898+
while (i < size && data[i] == '=')
1899+
{
1900+
i++;
1901+
c++;
1902+
}
18891903
while (i<size && data[i]==' ') i++;
18901904
int level = (c>1 && (i>=size || data[i]=='\n')) ? 1 : 0;
18911905
if (allowAdjustLevel && level==1 && indentLevel==-1)
@@ -1903,7 +1917,11 @@ int Markdown::Private::isHeaderline(std::string_view data, bool allowAdjustLevel
19031917
// test of level 2 header
19041918
if (data[i]=='-')
19051919
{
1906-
while (i<size && data[i]=='-') i++,c++;
1920+
while (i < size && data[i] == '-')
1921+
{
1922+
i++;
1923+
c++;
1924+
}
19071925
while (i<size && data[i]==' ') i++;
19081926
return (c>1 && (i>=size || data[i]=='\n')) ? indentLevel+2 : 0;
19091927
}
@@ -2107,12 +2125,20 @@ int Markdown::Private::isAtxHeader(std::string_view data,
21072125
{
21082126
return 0;
21092127
}
2110-
while (i<size && data[i]=='#') i++,level++;
2128+
while (i < size && data[i] == '#')
2129+
{
2130+
i++;
2131+
level++;
2132+
}
21112133
if (level>SectionType::MaxLevel) // too many #'s -> no section
21122134
{
21132135
return 0;
21142136
}
2115-
while (i<size && data[i]==' ') i++,blanks++;
2137+
while (i < size && data[i] == ' ')
2138+
{
2139+
i++;
2140+
blanks++;
2141+
}
21162142
if (level==1 && blanks==0)
21172143
{
21182144
return 0; // special case to prevent #someid seen as a header (see bug 671395)
@@ -2245,7 +2271,8 @@ static size_t computeIndentExcludingListMarkers(std::string_view data)
22452271
{ // end of indent
22462272
break;
22472273
}
2248-
indent++,i++;
2274+
indent++;
2275+
i++;
22492276
}
22502277
AUTO_TRACE_EXIT("result={}",indent);
22512278
return indent;
@@ -2303,15 +2330,23 @@ static bool isFencedCodeBlock(std::string_view data,size_t refIndent,
23032330
size_t indent=0;
23042331
int startTildes=0;
23052332
const size_t size = data.size();
2306-
while (i<size && data[i]==' ') indent++,i++;
2333+
while (i < size && data[i] == ' ')
2334+
{
2335+
indent++;
2336+
i++;
2337+
}
23072338
if (indent>=refIndent+4)
23082339
{
23092340
AUTO_TRACE_EXIT("result=false: content is part of code block indent={} refIndent={}",indent,refIndent);
23102341
return FALSE;
23112342
} // part of code block
23122343
char tildaChar='~';
23132344
if (i<size && data[i]=='`') tildaChar='`';
2314-
while (i<size && data[i]==tildaChar) startTildes++,i++;
2345+
while (i < size && data[i] == tildaChar)
2346+
{
2347+
startTildes++;
2348+
i++;
2349+
}
23152350
if (startTildes<3)
23162351
{
23172352
AUTO_TRACE_EXIT("result=false: no fence marker found #tildes={}",startTildes);
@@ -2357,7 +2392,11 @@ static bool isFencedCodeBlock(std::string_view data,size_t refIndent,
23572392
{
23582393
end=i;
23592394
int endTildes=0;
2360-
while (i<size && data[i]==tildaChar) endTildes++,i++;
2395+
while (i < size && data[i] == tildaChar)
2396+
{
2397+
endTildes++;
2398+
i++;
2399+
}
23612400
while (i<size && data[i]==' ') i++;
23622401
{
23632402
if (endTildes==startTildes)
@@ -2382,7 +2421,11 @@ static bool isCodeBlock(std::string_view data, size_t offset,size_t &indent)
23822421
size_t i=0;
23832422
size_t indent0=0;
23842423
const size_t size = data.size();
2385-
while (i<size && data[i]==' ') indent0++,i++;
2424+
while (i < size && data[i] == ' ')
2425+
{
2426+
indent0++;
2427+
i++;
2428+
}
23862429

23872430
if (indent0<codeBlockIndent)
23882431
{
@@ -2474,7 +2517,11 @@ static size_t findTableColumns(std::string_view data,size_t &start,size_t &end,s
24742517
size_t i=0,n=0;
24752518
// find start character of the table line
24762519
while (i<size && data[i]==' ') i++;
2477-
if (i<size && data[i]=='|' && data[i]!='\n') i++,n++; // leading | does not count
2520+
if (i < size && data[i] == '|' && data[i] != '\n')
2521+
{
2522+
i++;
2523+
n++; // leading | does not count
2524+
}
24782525
start = i;
24792526

24802527
// find end character of the table line
@@ -2484,7 +2531,11 @@ static size_t findTableColumns(std::string_view data,size_t &start,size_t &end,s
24842531

24852532
if (j>0 && i>0) i--; // move i to point before newline
24862533
while (i>0 && data[i]==' ') i--;
2487-
if (i>0 && data[i-1]!='\\' && data[i]=='|') i--,n++; // trailing or escaped | does not count
2534+
if (i > 0 && data[i - 1] != '\\' && data[i] == '|')
2535+
{
2536+
i--;
2537+
n++; // trailing or escaped | does not count
2538+
}
24882539
end = i;
24892540

24902541
// count columns between start and end
@@ -2970,7 +3021,11 @@ bool skipOverFileAndLineCommands(std::string_view data,size_t indent,size_t &off
29703021
i+=9;
29713022
location=data.substr(locStart,i-locStart);
29723023
location+='\n';
2973-
while (indent>0 && i<size && data[i]==' ') i++,indent--;
3024+
while (indent > 0 && i < size && data[i] == ' ')
3025+
{
3026+
i++;
3027+
indent--;
3028+
}
29743029
if (i<size && data[i]=='\n') i++;
29753030
offset = i;
29763031
return true;
@@ -2995,7 +3050,11 @@ size_t Markdown::Private::writeCodeBlock(std::string_view data,size_t refIndent)
29953050
while (end<=size && data[end-1]!='\n') end++;
29963051
size_t j=i;
29973052
size_t indent=0;
2998-
while (j<end && data[j]==' ') j++,indent++;
3053+
while (j < end && data[j] == ' ')
3054+
{
3055+
j++;
3056+
indent++;
3057+
}
29993058
//printf("j=%d end=%d indent=%d refIndent=%d tabSize=%d data={%s}\n",
30003059
// j,end,indent,refIndent,Config_getInt(TAB_SIZE),qPrint(QCString(data+i).left(end-i-1)));
30013060
if (j==end-1) // empty line
@@ -3101,12 +3160,20 @@ size_t Markdown::Private::findEndOfLine(std::string_view data,size_t offset)
31013160
}
31023161
else if (nb==0 && data[end-1]=='`')
31033162
{
3104-
while (end<=size && data[end-1]=='`') end++,nb++;
3163+
while (end <= size && data[end - 1] == '`')
3164+
{
3165+
end++;
3166+
nb++;
3167+
}
31053168
}
31063169
else if (nb>0 && data[end-1]=='`')
31073170
{
31083171
size_t enb=0;
3109-
while (end<=size && data[end-1]=='`') end++,enb++;
3172+
while (end <= size && data[end - 1] == '`')
3173+
{
3174+
end++;
3175+
enb++;
3176+
}
31103177
if (enb==nb) nb=0;
31113178
}
31123179
else

0 commit comments

Comments
 (0)