Skip to content

Commit

Permalink
#185 Minor changes to avoid warnings. Does not change behaviour.
Browse files Browse the repository at this point in the history
Use c++ headers, nullptr, const, noexcept, [[nodiscard]] where simple.
Remove unnecessary inline.
  • Loading branch information
nyamatongwe committed Jul 22, 2023
1 parent 32a2466 commit 5ffca56
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions lexers/LexHTML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cstdarg>

#include <string>
#include <string_view>
Expand Down Expand Up @@ -42,15 +42,15 @@ namespace {
enum script_type { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML, eScriptSGML, eScriptSGMLblock, eScriptComment };
enum script_mode { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc };

inline bool IsAWordChar(const int ch) {
bool IsAWordChar(const int ch) noexcept {
return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
}

inline bool IsAWordStart(const int ch) {
bool IsAWordStart(const int ch) noexcept {
return (ch < 0x80) && (isalnum(ch) || ch == '_');
}

inline bool IsOperator(int ch) {
bool IsOperator(int ch) noexcept {
if (IsASCII(ch) && isalnum(ch))
return false;
// '.' left out as it is used to make up numbers
Expand Down Expand Up @@ -131,7 +131,7 @@ int PrintScriptingIndicatorOffset(Accessor &styler, Sci_PositionU start, Sci_Pos
return iResult;
}

script_type ScriptOfState(int state) {
script_type ScriptOfState(int state) noexcept {
if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) {
return eScriptPython;
} else if ((state >= SCE_HB_START && state <= SCE_HB_STRINGEOL) || (state == SCE_H_ASPAT || state == SCE_H_XCCOMMENT)) {
Expand All @@ -149,7 +149,7 @@ script_type ScriptOfState(int state) {
}
}

int statePrintForState(int state, script_mode inScriptType) {
int statePrintForState(int state, script_mode inScriptType) noexcept {
int StateToPrint = state;

if (state >= SCE_HJ_START) {
Expand All @@ -165,7 +165,7 @@ int statePrintForState(int state, script_mode inScriptType) {
return StateToPrint;
}

int stateForPrintState(int StateToPrint) {
int stateForPrintState(int StateToPrint) noexcept {
int state;

if ((StateToPrint >= SCE_HPA_START) && (StateToPrint <= SCE_HPA_IDENTIFIER)) {
Expand All @@ -185,7 +185,7 @@ constexpr bool IsNumberChar(char ch) noexcept {
return IsADigit(ch) || ch == '.' || ch == '-' || ch == '#';
}

inline bool isStringState(int state) {
bool isStringState(int state) noexcept {
bool bResult;

switch (state) {
Expand Down Expand Up @@ -216,7 +216,7 @@ inline bool isStringState(int state) {
return bResult;
}

inline bool stateAllowsTermination(int state) {
bool stateAllowsTermination(int state) noexcept {
bool allowTermination = !isStringState(state);
if (allowTermination) {
switch (state) {
Expand All @@ -229,7 +229,7 @@ inline bool stateAllowsTermination(int state) {
return allowTermination;
}

inline bool isPreProcessorEndTag(int state, int ch) {
bool isPreProcessorEndTag(int state, int ch) {
const script_type type = ScriptOfState(state);
if (state == SCE_H_ASP || AnyOf(type, eScriptVBS, eScriptJS, eScriptPython)) {
return ch == '%';
Expand All @@ -241,7 +241,7 @@ inline bool isPreProcessorEndTag(int state, int ch) {
}

// not really well done, since it's only comments that should lex the %> and <%
inline bool isCommentASPState(int state) {
bool isCommentASPState(int state) noexcept {
bool bResult;

switch (state) {
Expand Down Expand Up @@ -444,7 +444,7 @@ bool isWordCdata(Sci_PositionU start, Sci_PositionU end, Accessor &styler) {
}

// Return the first state to reach when entering a scripting language
int StateForScript(script_type scriptLanguage) {
int StateForScript(script_type scriptLanguage) noexcept {
int Result;
switch (scriptLanguage) {
case eScriptVBS:
Expand Down Expand Up @@ -472,37 +472,37 @@ int StateForScript(script_type scriptLanguage) {
return Result;
}

inline bool issgmlwordchar(int ch) {
bool issgmlwordchar(int ch) noexcept {
return !IsASCII(ch) ||
(isalnum(ch) || ch == '.' || ch == '_' || ch == ':' || ch == '!' || ch == '#' || ch == '[');
}

inline bool IsPhpWordStart(int ch) {
bool IsPhpWordStart(int ch) noexcept {
return (IsASCII(ch) && (isalpha(ch) || (ch == '_'))) || (ch >= 0x7f);
}

inline bool IsPhpWordChar(int ch) {
bool IsPhpWordChar(int ch) noexcept {
return IsADigit(ch) || IsPhpWordStart(ch);
}

bool InTagState(int state) {
bool InTagState(int state) noexcept {
return state == SCE_H_TAG || state == SCE_H_TAGUNKNOWN ||
state == SCE_H_SCRIPT ||
state == SCE_H_ATTRIBUTE || state == SCE_H_ATTRIBUTEUNKNOWN ||
state == SCE_H_NUMBER || state == SCE_H_OTHER ||
state == SCE_H_DOUBLESTRING || state == SCE_H_SINGLESTRING;
}

bool IsCommentState(const int state) {
bool IsCommentState(const int state) noexcept {
return state == SCE_H_COMMENT || state == SCE_H_SGML_COMMENT;
}

bool IsScriptCommentState(const int state) {
bool IsScriptCommentState(const int state) noexcept {
return state == SCE_HJ_COMMENT || state == SCE_HJ_COMMENTLINE || state == SCE_HJA_COMMENT ||
state == SCE_HJA_COMMENTLINE || state == SCE_HB_COMMENTLINE || state == SCE_HBA_COMMENTLINE;
}

bool isLineEnd(int ch) {
bool isLineEnd(int ch) noexcept {
return ch == '\r' || ch == '\n';
}

Expand Down Expand Up @@ -556,8 +556,8 @@ class PhpNumberState {
bool exponentChar = false;

public:
inline bool isInvalid() { return invalid; }
inline bool isFinished() { return finished; }
[[nodiscard]] bool isInvalid() const noexcept { return invalid; }
[[nodiscard]] bool isFinished() const noexcept { return finished; }

bool init(int ch, int chPlus1, int chPlus2) {
base = BASE_10;
Expand Down Expand Up @@ -651,7 +651,7 @@ class PhpNumberState {
}
};

bool isPHPStringState(int state) {
bool isPHPStringState(int state) noexcept {
return
(state == SCE_HPHP_HSTRING) ||
(state == SCE_HPHP_SIMPLESTRING) ||
Expand Down Expand Up @@ -715,8 +715,6 @@ struct OptionsHTML {
bool foldComment = false;
bool foldHeredoc = false;
bool foldXmlAtTagOpen = false;
OptionsHTML() noexcept {
}
};

const char * const htmlWordListDesc[] = {
Expand All @@ -726,7 +724,7 @@ const char * const htmlWordListDesc[] = {
"Python keywords",
"PHP keywords",
"SGML and DTD keywords",
0,
nullptr,
};

const char * const phpscriptWordListDesc[] = {
Expand All @@ -736,7 +734,7 @@ const char * const phpscriptWordListDesc[] = {
"", //Unused
"PHP keywords",
"", //Unused
0,
nullptr,
};

struct OptionSetHTML : public OptionSet<OptionsHTML> {
Expand Down Expand Up @@ -787,7 +785,7 @@ struct OptionSetHTML : public OptionSet<OptionsHTML> {
}
};

LexicalClass lexicalClassesHTML[] = {
const LexicalClass lexicalClassesHTML[] = {
// Lexer HTML SCLEX_HTML SCE_H_ SCE_HJ_ SCE_HJA_ SCE_HB_ SCE_HBA_ SCE_HP_ SCE_HPHP_ SCE_HPA_:
0, "SCE_H_DEFAULT", "default", "Text",
1, "SCE_H_TAG", "tag", "Tags",
Expand Down Expand Up @@ -919,7 +917,7 @@ LexicalClass lexicalClassesHTML[] = {
127, "SCE_HPHP_OPERATOR", "server php operator", "PHP operator",
};

LexicalClass lexicalClassesXML[] = {
const LexicalClass lexicalClassesXML[] = {
// Lexer.Secondary XML SCLEX_XML SCE_H_:
0, "SCE_H_DEFAULT", "default", "Default",
1, "SCE_H_TAG", "tag", "Tags",
Expand Down Expand Up @@ -955,7 +953,7 @@ LexicalClass lexicalClassesXML[] = {
31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block",
};

const char *tagsThatDoNotFold[] = {
const char * const tagsThatDoNotFold[] = {
"area",
"base",
"basefont",
Expand Down Expand Up @@ -1047,7 +1045,7 @@ Sci_Position SCI_METHOD LexerHTML::PropertySet(const char *key, const char *val)
}

Sci_Position SCI_METHOD LexerHTML::WordListSet(int n, const char *wl) {
WordList *wordListN = 0;
WordList *wordListN = nullptr;
switch (n) {
case 0:
wordListN = &keywords;
Expand Down Expand Up @@ -1356,7 +1354,7 @@ void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int
// check if the closing tag is a script tag
if (const char *tag =
(state == SCE_HJ_COMMENTLINE || state == SCE_HB_COMMENTLINE || isXml) ? "script" :
state == SCE_H_COMMENT ? "comment" : 0) {
state == SCE_H_COMMENT ? "comment" : nullptr) {
Sci_Position j = i + 2;
int chr;
do {
Expand Down

0 comments on commit 5ffca56

Please sign in to comment.