Skip to content

Commit 23a0872

Browse files
committed
Simple modernisation using const, noexcept, nullptr, =default, [[nodiscard]] reduces warnings from clang-tidy and cppcheck.
1 parent e54046d commit 23a0872

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

cppcheck.suppress

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ knownConditionTrueFalse:lexilla/lexers/LexHex.cxx
102102
constVariable:lexilla/lexers/LexHollywood.cxx
103103
variableScope:lexilla/lexers/LexInno.cxx
104104
constVariableReference:lexilla/lexers/LexInno.cxx
105-
constParameterReference:lexilla/lexers/LexJSON.cxx
106105
constParameterPointer:lexilla/lexers/LexJulia.cxx
107106
constParameterReference:lexilla/lexers/LexJulia.cxx
108107
knownConditionTrueFalse:lexilla/lexers/LexJulia.cxx

lexers/LexJSON.cxx

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace {
4040
const char *const JSONWordListDesc[] = {
4141
"JSON Keywords",
4242
"JSON-LD Keywords",
43-
0
43+
nullptr
4444
};
4545

4646
/**
@@ -58,18 +58,18 @@ struct CompactIRI {
5858
foundInvalidChar = false;
5959
setCompactIRI = CharacterSet(CharacterSet::setAlpha, "$_-");
6060
}
61-
void resetState() {
61+
void resetState() noexcept {
6262
colonCount = 0;
6363
foundInvalidChar = false;
6464
}
65-
void checkChar(int ch) {
65+
void checkChar(int ch) noexcept {
6666
if (ch == ':') {
6767
colonCount++;
6868
} else {
6969
foundInvalidChar |= !setCompactIRI.Contains(ch);
7070
}
7171
}
72-
bool shouldHighlight() const {
72+
[[nodiscard]] bool shouldHighlight() const noexcept {
7373
return !foundInvalidChar && colonCount == 1;
7474
}
7575
};
@@ -89,7 +89,7 @@ struct EscapeSequence {
8989
setEscapeChars = CharacterSet(CharacterSet::setNone, "\\\"tnbfru/");
9090
}
9191
// Returns true if the following character is a valid escaped character
92-
bool newSequence(int nextChar) {
92+
bool newSequence(int nextChar) noexcept {
9393
digitsLeft = 0;
9494
if (nextChar == 'u') {
9595
digitsLeft = 5;
@@ -98,10 +98,10 @@ struct EscapeSequence {
9898
}
9999
return true;
100100
}
101-
bool atEscapeEnd() const {
101+
[[nodiscard]] bool atEscapeEnd() const noexcept {
102102
return digitsLeft <= 0;
103103
}
104-
bool isInvalidChar(int currChar) const {
104+
[[nodiscard]] bool isInvalidChar(int currChar) const noexcept {
105105
return !setHexDigits.Contains(currChar);
106106
}
107107
};
@@ -149,9 +149,9 @@ class LexerJSON : public DefaultLexer {
149149
Sci_Position i = 0;
150150
while (i < 50) {
151151
i++;
152-
char curr = styler.SafeGetCharAt(start+i, '\0');
153-
char next = styler.SafeGetCharAt(start+i+1, '\0');
154-
bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n');
152+
const char curr = styler.SafeGetCharAt(start+i, '\0');
153+
const char next = styler.SafeGetCharAt(start+i+1, '\0');
154+
const bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n');
155155
if (curr == ch) {
156156
return true;
157157
} else if (!isspacechar(curr) || atEOL) {
@@ -173,7 +173,7 @@ class LexerJSON : public DefaultLexer {
173173
bool escaped = false;
174174
while (i < 100) {
175175
i++;
176-
char curr = styler.SafeGetCharAt(start+i, '\0');
176+
const char curr = styler.SafeGetCharAt(start+i, '\0');
177177
if (escaped) {
178178
escaped = false;
179179
continue;
@@ -188,13 +188,13 @@ class LexerJSON : public DefaultLexer {
188188
return false;
189189
}
190190

191-
static bool IsNextWordInList(WordList &keywordList, CharacterSet wordSet,
192-
StyleContext &context, LexAccessor &styler) {
191+
static bool IsNextWordInList(const WordList &keywordList, const CharacterSet &wordSet,
192+
const StyleContext &context, LexAccessor &styler) {
193193
char word[51];
194-
Sci_Position currPos = (Sci_Position) context.currentPos;
194+
const Sci_Position currPos = static_cast<Sci_Position>(context.currentPos);
195195
int i = 0;
196196
while (i < 50) {
197-
char ch = styler.SafeGetCharAt(currPos + i);
197+
const char ch = styler.SafeGetCharAt(currPos + i);
198198
if (!wordSet.Contains(ch)) {
199199
break;
200200
}
@@ -213,7 +213,7 @@ class LexerJSON : public DefaultLexer {
213213
setKeywordJSONLD(CharacterSet::setAlpha, ":@"),
214214
setKeywordJSON(CharacterSet::setAlpha, "$_") {
215215
}
216-
virtual ~LexerJSON() {}
216+
virtual ~LexerJSON() = default;
217217
int SCI_METHOD Version() const override {
218218
return lvRelease5;
219219
}
@@ -239,7 +239,7 @@ class LexerJSON : public DefaultLexer {
239239
return optSetJSON.PropertyGet(key);
240240
}
241241
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override {
242-
WordList *wordListN = 0;
242+
WordList *wordListN = nullptr;
243243
switch (n) {
244244
case 0:
245245
wordListN = &keywordsJSON;
@@ -257,7 +257,7 @@ class LexerJSON : public DefaultLexer {
257257
return firstModification;
258258
}
259259
void *SCI_METHOD PrivateCall(int, void *) override {
260-
return 0;
260+
return nullptr;
261261
}
262262
static ILexer5 *LexerFactoryJSON() {
263263
return new LexerJSON;
@@ -404,7 +404,7 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos,
404404
if (context.ch == '"') {
405405
compactIRI.resetState();
406406
context.SetState(SCE_JSON_STRING);
407-
Sci_Position currPos = static_cast<Sci_Position>(context.currentPos);
407+
const Sci_Position currPos = static_cast<Sci_Position>(context.currentPos);
408408
if (AtPropertyName(styler, currPos)) {
409409
context.SetState(SCE_JSON_PROPERTYNAME);
410410
}
@@ -420,30 +420,30 @@ void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos,
420420
context.SetState(SCE_JSON_KEYWORD);
421421
}
422422
}
423-
bool numberStart =
423+
const bool numberStart =
424424
IsADigit(context.ch) && (context.chPrev == '+'||
425425
context.chPrev == '-' ||
426426
context.atLineStart ||
427427
IsASpace(context.chPrev) ||
428428
setOperators.Contains(context.chPrev));
429-
bool exponentPart =
429+
const bool exponentPart =
430430
tolower(context.ch) == 'e' &&
431431
IsADigit(context.chPrev) &&
432432
(IsADigit(context.chNext) ||
433433
context.chNext == '+' ||
434434
context.chNext == '-');
435-
bool signPart =
435+
const bool signPart =
436436
(context.ch == '-' || context.ch == '+') &&
437437
((tolower(context.chPrev) == 'e' && IsADigit(context.chNext)) ||
438438
((IsASpace(context.chPrev) || setOperators.Contains(context.chPrev))
439439
&& IsADigit(context.chNext)));
440-
bool adjacentDigit =
440+
const bool adjacentDigit =
441441
IsADigit(context.ch) && IsADigit(context.chPrev);
442-
bool afterExponent = IsADigit(context.ch) && tolower(context.chPrev) == 'e';
443-
bool dotPart = context.ch == '.' &&
442+
const bool afterExponent = IsADigit(context.ch) && tolower(context.chPrev) == 'e';
443+
const bool dotPart = context.ch == '.' &&
444444
IsADigit(context.chPrev) &&
445445
IsADigit(context.chNext);
446-
bool afterDot = IsADigit(context.ch) && context.chPrev == '.';
446+
const bool afterDot = IsADigit(context.ch) && context.chPrev == '.';
447447
if (numberStart ||
448448
exponentPart ||
449449
signPart ||
@@ -470,16 +470,16 @@ void SCI_METHOD LexerJSON::Fold(Sci_PositionU startPos,
470470
}
471471
LexAccessor styler(pAccess);
472472
Sci_PositionU currLine = styler.GetLine(startPos);
473-
Sci_PositionU endPos = startPos + length;
473+
const Sci_PositionU endPos = startPos + length;
474474
int currLevel = SC_FOLDLEVELBASE;
475475
if (currLine > 0)
476476
currLevel = styler.LevelAt(currLine - 1) >> 16;
477477
int nextLevel = currLevel;
478478
int visibleChars = 0;
479479
for (Sci_PositionU i = startPos; i < endPos; i++) {
480-
char curr = styler.SafeGetCharAt(i);
481-
char next = styler.SafeGetCharAt(i+1);
482-
bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n');
480+
const char curr = styler.SafeGetCharAt(i);
481+
const char next = styler.SafeGetCharAt(i+1);
482+
const bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n');
483483
if (styler.StyleAt(i) == SCE_JSON_OPERATOR) {
484484
if (curr == '{' || curr == '[') {
485485
nextLevel++;

0 commit comments

Comments
 (0)