Skip to content

Commit 242462e

Browse files
committed
Refactoring: replace qstrncmp(s,"literal",7)==0 by literal_at(s,"literal")
1 parent bd31ab7 commit 242462e

File tree

12 files changed

+57
-36
lines changed

12 files changed

+57
-36
lines changed

src/commentscan.l

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4375,7 +4375,7 @@ static void stripTrailingWhiteSpace(QCString &s)
43754375
{
43764376
i--;
43774377
}
4378-
else if (c=='r' && i>=7 && qstrncmp("\\ilinebr",s.data()+i-7,8)==0) // special line break marker
4378+
else if (c=='r' && i>=7 && literal_at(s.data()+i-7,"\\ilinebr")) // special line break marker
43794379
{
43804380
i-=8;
43814381
}

src/docparser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "util.h"
3939
#include "indexlist.h"
4040
#include "trace.h"
41+
#include "stringutil.h"
4142

4243
#if !ENABLE_DOCPARSER_TRACING
4344
#undef AUTO_TRACE
@@ -1779,7 +1780,7 @@ static QCString extractCopyDocId(const char *data, size_t &j, size_t len)
17791780
found=(round==0);
17801781
break;
17811782
case ' ': // allow spaces in cast operator (see issue #11169)
1782-
found=(round==0) && (j<8 || qstrncmp(data+j-8,"operator",8)!=0);
1783+
found=(round==0) && (j<8 || !literal_at(data+j-8,"operator"));
17831784
break;
17841785
}
17851786
}
@@ -1801,11 +1802,11 @@ static QCString extractCopyDocId(const char *data, size_t &j, size_t len)
18011802
}
18021803

18031804
// include const and volatile
1804-
if (qstrncmp(data+j," const",6)==0)
1805+
if (literal_at(data+j," const"))
18051806
{
18061807
j+=6;
18071808
}
1808-
else if (qstrncmp(data+j," volatile",9)==0)
1809+
else if (literal_at(data+j," volatile"))
18091810
{
18101811
j+=9;
18111812
}
@@ -1829,7 +1830,7 @@ static QCString extractCopyDocId(const char *data, size_t &j, size_t len)
18291830
// and the sizeof(str) returns the size of str including the '\0' terminator;
18301831
// a fact we abuse to skip over the start of the command character.
18311832
#define CHECK_FOR_COMMAND(str,action) \
1832-
do if ((i+sizeof(str)<len) && qstrncmp(data+i+1,str,sizeof(str)-1)==0) \
1833+
do if ((i+sizeof(str)<len) && literal_at(data+i+1,str)) \
18331834
{ j=i+sizeof(str); action; } while(0)
18341835

18351836
static size_t isCopyBriefOrDetailsCmd(const char *data, size_t i,size_t len,bool &brief)

src/doctokenizer.l

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef yyguts_t *yyscan_t;
4848
#include "regex.h"
4949
#include "debug.h"
5050
#include "docnode.h"
51+
#include "stringutil.h"
5152

5253
#define YY_NO_INPUT 1
5354
#define YY_NO_UNISTD_H 1
@@ -138,7 +139,7 @@ static int computeIndent(const char *str,size_t length)
138139
{
139140
indent=0;
140141
}
141-
else if (str[i]=='\\' && qstrncmp(str+i+1,"ilinebr",7)==0)
142+
else if (literal_at(&str[i],"\\ilinebr"))
142143
{
143144
indent=0;
144145
i+=7;

src/dotfilepatcher.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "dot.h"
2525
#include "dir.h"
2626
#include "portable.h"
27+
#include "stringutil.h"
2728

2829
// top part of the interactive SVG header
2930
static const char svgZoomHeader0[] = R"svg(
@@ -552,7 +553,7 @@ static bool readSVGSize(const QCString &fileName,int *width,int *height)
552553
std::string line;
553554
while (getline(f,line) && !found)
554555
{
555-
if (qstrncmp(line.c_str(),"<!--zoomable ",13)==0)
556+
if (literal_at(line.c_str(),"<!--zoomable "))
556557
{
557558
*width=-1;
558559
*height=-1;

src/htmlgen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "datetime.h"
5757
#include "portable.h"
5858
#include "outputlist.h"
59+
#include "stringutil.h"
5960

6061
//#define DBG_HTML(x) x;
6162
#define DBG_HTML(x)
@@ -172,11 +173,11 @@ static QCString getConvertLatexMacro()
172173
return "";
173174
}
174175
i++;
175-
if (!qstrncmp(data + i, "newcommand", strlen("newcommand")))
176+
if (literal_at(data+i,"newcommand"))
176177
{
177178
i += strlen("newcommand");
178179
}
179-
else if (!qstrncmp(data + i, "renewcommand", strlen("renewcommand")))
180+
else if (literal_at(data+i,"renewcommand"))
180181
{
181182
i += strlen("renewcommand");
182183
}

src/markdown.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ inline size_t isNewline(std::string_view data)
209209
// normal newline
210210
if (data[0] == '\n') return 1;
211211
// artificial new line from ^^ in ALIASES
212-
if (data[0] == '\\' && qstrncmp(data.data()+1,"ilinebr ",7)==0) return data[8]==' ' ? 9 : 8;
212+
if (literal_at(data,"\\ilinebr ")) return 8;
213213
return 0;
214214
}
215215

@@ -551,10 +551,7 @@ size_t Markdown::Private::isSpecialCommand(std::string_view data,size_t offset)
551551
// skip over name (and optionally type)
552552
while (offset_<data_.size() && (c=data_[offset_])!='\n' && (allowSpaces || c!=' ') && c!='(')
553553
{
554-
if (offset_+9<data_.size() && data_[offset_]=='\\')
555-
{
556-
if (qstrncmp(&data_[offset_+1],"ilinebr ",8)==0) break;
557-
}
554+
if (literal_at(data_.substr(offset_),"\\ilinebr ")) break;
558555
offset_++;
559556
}
560557
if (c=='(') // find the end of the function
@@ -959,13 +956,13 @@ int Markdown::Private::processNmdash(std::string_view data,size_t offset)
959956
{
960957
count++;
961958
}
962-
if (count>=2 && offset>=2 && qstrncmp(data.data()-2,"<!",2)==0)
959+
if (count>=2 && offset>=2 && literal_at(data.data()-2,"<!"))
963960
{ AUTO_TRACE_EXIT("result={}",1-count); return 1-count; } // start HTML comment
964961
if (count==2 && size > 2 && data[2]=='>')
965962
{ return 0; } // end HTML comment
966963
if (count==3 && size > 3 && data[3]=='>')
967964
{ return 0; } // end HTML comment
968-
if (count==2 && (offset<8 || qstrncmp(data.data()-8,"operator",8)!=0)) // -- => ndash
965+
if (count==2 && (offset<8 || !literal_at(data.data()-8,"operator"))) // -- => ndash
969966
{
970967
out+="&ndash;";
971968
AUTO_TRACE_EXIT("result=2");
@@ -2890,15 +2887,15 @@ bool skipOverFileAndLineCommands(std::string_view data,size_t indent,size_t &off
28902887
size_t i = offset;
28912888
size_t size = data.size();
28922889
while (i<data.size() && data[i]==' ') i++;
2893-
if (i<size+8 && data[i]=='\\' && qstrncmp(&data[i+1],"ifile \"",7)==0)
2890+
if (literal_at(data.substr(i),"\\ifile \""))
28942891
{
28952892
size_t locStart = i;
28962893
if (i>offset) locStart--; // include the space before \ifile
28972894
i+=8;
28982895
bool found=false;
28992896
while (i+9<size && data[i]!='\n')
29002897
{
2901-
if (data[i]=='\\' && qstrncmp(&data[i+1],"ilinebr ",8)==0)
2898+
if (literal_at(data.substr(i),"\\ilinebr "))
29022899
{
29032900
found=true;
29042901
break;
@@ -3459,7 +3456,7 @@ static ExplicitPageResult isExplicitPage(const QCString &docs)
34593456
{
34603457
i++;
34613458
}
3462-
if (i+5<size && data[i]=='<' && qstrncmp(&data[i],"<!--!",5)==0) // skip over <!--! marker
3459+
if (literal_at(data.substr(i),"<!--!")) // skip over <!--! marker
34633460
{
34643461
i+=5;
34653462
while (i<size && (data[i]==' ' || data[i]=='\n')) // skip over spaces after the <!--! marker
@@ -3469,10 +3466,10 @@ static ExplicitPageResult isExplicitPage(const QCString &docs)
34693466
}
34703467
if (i+1<size &&
34713468
(data[i]=='\\' || data[i]=='@') &&
3472-
(qstrncmp(&data[i+1],"page ",5)==0 || qstrncmp(&data[i+1],"mainpage",8)==0)
3469+
(literal_at(data.substr(i+1),"page ") || literal_at(data.substr(i+1),"mainpage"))
34733470
)
34743471
{
3475-
if (qstrncmp(&data[i+1],"page ",5)==0)
3472+
if (literal_at(data.substr(i+1),"page "))
34763473
{
34773474
AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitPage");
34783475
return ExplicitPageResult::explicitPage;
@@ -3485,7 +3482,7 @@ static ExplicitPageResult isExplicitPage(const QCString &docs)
34853482
}
34863483
else if (i+1<size &&
34873484
(data[i]=='\\' || data[i]=='@') &&
3488-
(qstrncmp(&data[i+1],"dir\n",4)==0 || qstrncmp(&data[i+1],"dir ",4)==0)
3485+
(literal_at(data.substr(i+1),"dir\n") || literal_at(data.substr(i+1),"dir "))
34893486
)
34903487
{
34913488
AUTO_TRACE_EXIT("result=ExplicitPageResult::explicitDirPage");
@@ -3588,7 +3585,7 @@ QCString Markdown::process(const QCString &input, int &startNewlines, bool fromP
35883585
{
35893586
while (*p==' ') p++; // skip over spaces
35903587
while (*p=='\n') {startNewlines++;p++;}; // skip over newlines
3591-
if (qstrncmp(p,"<br>",4)==0) p+=4; // skip over <br>
3588+
if (literal_at(p,"<br>")) p+=4; // skip over <br>
35923589
}
35933590
if (p>result.data())
35943591
{

src/msc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "mscgen_api.h"
2626
#include "dir.h"
2727
#include "textstream.h"
28+
#include "stringutil.h"
2829

2930
static const int maxCmdLine = 40960;
3031

@@ -48,7 +49,7 @@ static bool convertMapFile(TextStream &t,const QCString &mapName,const QCString
4849
{
4950
bool isRef = false;
5051
//printf("ReadLine '%s'\n",line.c_str());
51-
if (qstrncmp(line.c_str(),"rect",4)==0)
52+
if (literal_at(line.c_str(),"rect"))
5253
{
5354
// obtain the url and the coordinates in the order used by graphviz-1.5
5455
sscanf(line.c_str(),"rect %s %d,%d %d,%d",url,&x1,&y1,&x2,&y2);

src/plantuml.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "fileinfo.h"
2424
#include "dir.h"
2525
#include "indexlist.h"
26+
#include "stringutil.h"
2627

2728
QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,
2829
const QCString &content,OutputFormat format, const QCString &engine,
@@ -94,7 +95,7 @@ QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QC
9495
case '\t': break;
9596
case ' ': break;
9697
case '@':
97-
if (initial && qstrncmp(p,"start",5)==0) // @start...
98+
if (initial && literal_at(p,"start")) // @start...
9899
{
99100
while ((c=*p++) && isId(c)) text+=c;
100101
// insert the image name

src/pre.l

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ typedef yyguts_t *yyscan_t;
6363
#include "fileinfo.h"
6464
#include "trace.h"
6565
#include "debug.h"
66+
#include "stringutil.h"
6667

6768
#define YY_NO_UNISTD_H 1
6869

@@ -3159,7 +3160,7 @@ static QCString removeIdsAndMarkers(const QCString &s)
31593160
continue;
31603161
}
31613162
}
3162-
else if (c=='s' && qstrncmp(p,"sizeof",6)==0) // sizeof(...)
3163+
else if (c=='s' && literal_at(p,"sizeof")) // sizeof(...)
31633164
{
31643165
const char *q = p+6;
31653166
while (*q==' ' || *q=='\t') q++;
@@ -3200,7 +3201,7 @@ static QCString removeIdsAndMarkers(const QCString &s)
32003201
}
32013202
else if (c=='d' && !inNum) // identifier starting with a 'd'
32023203
{
3203-
if (qstrncmp(p,"defined ",8)==0 || qstrncmp(p,"defined(",8)==0)
3204+
if (literal_at(p,"defined ") || literal_at(p,"defined("))
32043205
// defined keyword
32053206
{
32063207
p+=7; // skip defined

src/scanner.l

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef yyguts_t *yyscan_t;
5050
#include "commentscan.h"
5151
#include "arguments.h"
5252
#include "moduledef.h"
53+
#include "stringutil.h"
5354

5455
#include "clangparser.h"
5556
#include "markdown.h"
@@ -984,7 +985,7 @@ NONLopt [^\n]*
984985
yyextra->roundCount=0;
985986
BEGIN( SkipRound );
986987
}
987-
else if (qstrncmp(yytext,"@property",9)==0) // ObjC 2.0 property
988+
else if (literal_at(yytext,"@property")) // ObjC 2.0 property
988989
{
989990
yyextra->current->mtype = yyextra->mtype = MethodTypes::Property;
990991
yyextra->current->spec.setReadable(true).setWritable(true).setAssign(true);
@@ -6079,7 +6080,7 @@ NONLopt [^\n]*
60796080
BEGIN( ClassVar );
60806081
}
60816082
<ClassVar>{SCOPENAME}{BNopt}/"(" {
6082-
if (yyextra->insideIDL && qstrncmp(yytext,"switch",6)==0 && !isId(yytext[6]))
6083+
if (yyextra->insideIDL && literal_at(yytext,"switch") && !isId(yytext[6]))
60836084
{
60846085
// Corba IDL style union
60856086
yyextra->roundCount=0;

0 commit comments

Comments
 (0)